├── IERC20.json ├── IERC20 └── IERC20.swift ├── PancakeSwap.json ├── PancakeSwap ├── PancakeSwap.swift ├── PancakeSwapFunctions.swift └── PancakeSwapResponses.swift ├── README.md ├── package-lock.json ├── package.json └── start.js /IERC20.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [], 4 | "payable": false, 5 | "stateMutability": "nonpayable", 6 | "type": "constructor" 7 | }, 8 | { 9 | "anonymous": false, 10 | "inputs": [ 11 | { 12 | "indexed": true, 13 | "internalType": "address", 14 | "name": "owner", 15 | "type": "address" 16 | }, 17 | { 18 | "indexed": true, 19 | "internalType": "address", 20 | "name": "spender", 21 | "type": "address" 22 | }, 23 | { 24 | "indexed": false, 25 | "internalType": "uint256", 26 | "name": "value", 27 | "type": "uint256" 28 | } 29 | ], 30 | "name": "Approval", 31 | "type": "event" 32 | }, 33 | { 34 | "anonymous": false, 35 | "inputs": [ 36 | { 37 | "indexed": true, 38 | "internalType": "address", 39 | "name": "previousOwner", 40 | "type": "address" 41 | }, 42 | { 43 | "indexed": true, 44 | "internalType": "address", 45 | "name": "newOwner", 46 | "type": "address" 47 | } 48 | ], 49 | "name": "OwnershipTransferred", 50 | "type": "event" 51 | }, 52 | { 53 | "anonymous": false, 54 | "inputs": [ 55 | { 56 | "indexed": true, 57 | "internalType": "address", 58 | "name": "from", 59 | "type": "address" 60 | }, 61 | { 62 | "indexed": true, 63 | "internalType": "address", 64 | "name": "to", 65 | "type": "address" 66 | }, 67 | { 68 | "indexed": false, 69 | "internalType": "uint256", 70 | "name": "value", 71 | "type": "uint256" 72 | } 73 | ], 74 | "name": "Transfer", 75 | "type": "event" 76 | }, 77 | { 78 | "constant": true, 79 | "inputs": [], 80 | "name": "_decimals", 81 | "outputs": [ 82 | { 83 | "internalType": "uint8", 84 | "name": "", 85 | "type": "uint8" 86 | } 87 | ], 88 | "payable": false, 89 | "stateMutability": "view", 90 | "type": "function" 91 | }, 92 | { 93 | "constant": true, 94 | "inputs": [], 95 | "name": "_name", 96 | "outputs": [ 97 | { 98 | "internalType": "string", 99 | "name": "", 100 | "type": "string" 101 | } 102 | ], 103 | "payable": false, 104 | "stateMutability": "view", 105 | "type": "function" 106 | }, 107 | { 108 | "constant": true, 109 | "inputs": [], 110 | "name": "_symbol", 111 | "outputs": [ 112 | { 113 | "internalType": "string", 114 | "name": "", 115 | "type": "string" 116 | } 117 | ], 118 | "payable": false, 119 | "stateMutability": "view", 120 | "type": "function" 121 | }, 122 | { 123 | "constant": true, 124 | "inputs": [ 125 | { 126 | "internalType": "address", 127 | "name": "owner", 128 | "type": "address" 129 | }, 130 | { 131 | "internalType": "address", 132 | "name": "spender", 133 | "type": "address" 134 | } 135 | ], 136 | "name": "allowance", 137 | "outputs": [ 138 | { 139 | "internalType": "uint256", 140 | "name": "", 141 | "type": "uint256" 142 | } 143 | ], 144 | "payable": false, 145 | "stateMutability": "view", 146 | "type": "function" 147 | }, 148 | { 149 | "constant": false, 150 | "inputs": [ 151 | { 152 | "internalType": "address", 153 | "name": "spender", 154 | "type": "address" 155 | }, 156 | { 157 | "internalType": "uint256", 158 | "name": "amount", 159 | "type": "uint256" 160 | } 161 | ], 162 | "name": "approve", 163 | "outputs": [ 164 | { 165 | "internalType": "bool", 166 | "name": "", 167 | "type": "bool" 168 | } 169 | ], 170 | "payable": false, 171 | "stateMutability": "nonpayable", 172 | "type": "function" 173 | }, 174 | { 175 | "constant": true, 176 | "inputs": [ 177 | { 178 | "internalType": "address", 179 | "name": "account", 180 | "type": "address" 181 | } 182 | ], 183 | "name": "balanceOf", 184 | "outputs": [ 185 | { 186 | "internalType": "uint256", 187 | "name": "", 188 | "type": "uint256" 189 | } 190 | ], 191 | "payable": false, 192 | "stateMutability": "view", 193 | "type": "function" 194 | }, 195 | { 196 | "constant": false, 197 | "inputs": [ 198 | { 199 | "internalType": "uint256", 200 | "name": "amount", 201 | "type": "uint256" 202 | } 203 | ], 204 | "name": "burn", 205 | "outputs": [ 206 | { 207 | "internalType": "bool", 208 | "name": "", 209 | "type": "bool" 210 | } 211 | ], 212 | "payable": false, 213 | "stateMutability": "nonpayable", 214 | "type": "function" 215 | }, 216 | { 217 | "constant": true, 218 | "inputs": [], 219 | "name": "decimals", 220 | "outputs": [ 221 | { 222 | "internalType": "uint8", 223 | "name": "", 224 | "type": "uint8" 225 | } 226 | ], 227 | "payable": false, 228 | "stateMutability": "view", 229 | "type": "function" 230 | }, 231 | { 232 | "constant": false, 233 | "inputs": [ 234 | { 235 | "internalType": "address", 236 | "name": "spender", 237 | "type": "address" 238 | }, 239 | { 240 | "internalType": "uint256", 241 | "name": "subtractedValue", 242 | "type": "uint256" 243 | } 244 | ], 245 | "name": "decreaseAllowance", 246 | "outputs": [ 247 | { 248 | "internalType": "bool", 249 | "name": "", 250 | "type": "bool" 251 | } 252 | ], 253 | "payable": false, 254 | "stateMutability": "nonpayable", 255 | "type": "function" 256 | }, 257 | { 258 | "constant": true, 259 | "inputs": [], 260 | "name": "getOwner", 261 | "outputs": [ 262 | { 263 | "internalType": "address", 264 | "name": "", 265 | "type": "address" 266 | } 267 | ], 268 | "payable": false, 269 | "stateMutability": "view", 270 | "type": "function" 271 | }, 272 | { 273 | "constant": false, 274 | "inputs": [ 275 | { 276 | "internalType": "address", 277 | "name": "spender", 278 | "type": "address" 279 | }, 280 | { 281 | "internalType": "uint256", 282 | "name": "addedValue", 283 | "type": "uint256" 284 | } 285 | ], 286 | "name": "increaseAllowance", 287 | "outputs": [ 288 | { 289 | "internalType": "bool", 290 | "name": "", 291 | "type": "bool" 292 | } 293 | ], 294 | "payable": false, 295 | "stateMutability": "nonpayable", 296 | "type": "function" 297 | }, 298 | { 299 | "constant": false, 300 | "inputs": [ 301 | { 302 | "internalType": "uint256", 303 | "name": "amount", 304 | "type": "uint256" 305 | } 306 | ], 307 | "name": "mint", 308 | "outputs": [ 309 | { 310 | "internalType": "bool", 311 | "name": "", 312 | "type": "bool" 313 | } 314 | ], 315 | "payable": false, 316 | "stateMutability": "nonpayable", 317 | "type": "function" 318 | }, 319 | { 320 | "constant": true, 321 | "inputs": [], 322 | "name": "name", 323 | "outputs": [ 324 | { 325 | "internalType": "string", 326 | "name": "", 327 | "type": "string" 328 | } 329 | ], 330 | "payable": false, 331 | "stateMutability": "view", 332 | "type": "function" 333 | }, 334 | { 335 | "constant": true, 336 | "inputs": [], 337 | "name": "owner", 338 | "outputs": [ 339 | { 340 | "internalType": "address", 341 | "name": "", 342 | "type": "address" 343 | } 344 | ], 345 | "payable": false, 346 | "stateMutability": "view", 347 | "type": "function" 348 | }, 349 | { 350 | "constant": false, 351 | "inputs": [], 352 | "name": "renounceOwnership", 353 | "outputs": [], 354 | "payable": false, 355 | "stateMutability": "nonpayable", 356 | "type": "function" 357 | }, 358 | { 359 | "constant": true, 360 | "inputs": [], 361 | "name": "symbol", 362 | "outputs": [ 363 | { 364 | "internalType": "string", 365 | "name": "", 366 | "type": "string" 367 | } 368 | ], 369 | "payable": false, 370 | "stateMutability": "view", 371 | "type": "function" 372 | }, 373 | { 374 | "constant": true, 375 | "inputs": [], 376 | "name": "totalSupply", 377 | "outputs": [ 378 | { 379 | "internalType": "uint256", 380 | "name": "", 381 | "type": "uint256" 382 | } 383 | ], 384 | "payable": false, 385 | "stateMutability": "view", 386 | "type": "function" 387 | }, 388 | { 389 | "constant": false, 390 | "inputs": [ 391 | { 392 | "internalType": "address", 393 | "name": "recipient", 394 | "type": "address" 395 | }, 396 | { 397 | "internalType": "uint256", 398 | "name": "amount", 399 | "type": "uint256" 400 | } 401 | ], 402 | "name": "transfer", 403 | "outputs": [ 404 | { 405 | "internalType": "bool", 406 | "name": "", 407 | "type": "bool" 408 | } 409 | ], 410 | "payable": false, 411 | "stateMutability": "nonpayable", 412 | "type": "function" 413 | }, 414 | { 415 | "constant": false, 416 | "inputs": [ 417 | { 418 | "internalType": "address", 419 | "name": "sender", 420 | "type": "address" 421 | }, 422 | { 423 | "internalType": "address", 424 | "name": "recipient", 425 | "type": "address" 426 | }, 427 | { 428 | "internalType": "uint256", 429 | "name": "amount", 430 | "type": "uint256" 431 | } 432 | ], 433 | "name": "transferFrom", 434 | "outputs": [ 435 | { 436 | "internalType": "bool", 437 | "name": "", 438 | "type": "bool" 439 | } 440 | ], 441 | "payable": false, 442 | "stateMutability": "nonpayable", 443 | "type": "function" 444 | }, 445 | { 446 | "constant": false, 447 | "inputs": [ 448 | { 449 | "internalType": "address", 450 | "name": "newOwner", 451 | "type": "address" 452 | } 453 | ], 454 | "name": "transferOwnership", 455 | "outputs": [], 456 | "payable": false, 457 | "stateMutability": "nonpayable", 458 | "type": "function" 459 | } 460 | ] -------------------------------------------------------------------------------- /IERC20/IERC20.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // swiftAbi 4 | // Don't change the files! this file is generated! 5 | // https://github.com/imanrep/ 6 | // 7 | 8 | import BigInt 9 | import Foundation 10 | import web3 11 | 12 | public protocol IERC20Protocol { 13 | init(client: EthereumClientProtocol) 14 | 15 | func _decimals(contractAddress: EthereumAddress ) async throws -> BigUInt 16 | func _name(contractAddress: EthereumAddress ) async throws -> String 17 | func _symbol(contractAddress: EthereumAddress ) async throws -> String 18 | func allowance(contractAddress: EthereumAddress , owner: EthereumAddress, spender: EthereumAddress ) async throws -> BigUInt 19 | func approve(contractAddress: EthereumAddress , spender: EthereumAddress, amount: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 20 | func balanceOf(contractAddress: EthereumAddress , account: EthereumAddress ) async throws -> BigUInt 21 | func burn(contractAddress: EthereumAddress , amount: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 22 | func decimals(contractAddress: EthereumAddress ) async throws -> BigUInt 23 | func decreaseAllowance(contractAddress: EthereumAddress , spender: EthereumAddress, subtractedValue: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 24 | func getOwner(contractAddress: EthereumAddress ) async throws -> EthereumAddress 25 | func increaseAllowance(contractAddress: EthereumAddress , spender: EthereumAddress, addedValue: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 26 | func mint(contractAddress: EthereumAddress , amount: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 27 | func name(contractAddress: EthereumAddress ) async throws -> String 28 | func owner(contractAddress: EthereumAddress ) async throws -> EthereumAddress 29 | func symbol(contractAddress: EthereumAddress ) async throws -> String 30 | func totalSupply(contractAddress: EthereumAddress ) async throws -> BigUInt 31 | func transfer(contractAddress: EthereumAddress , recipient: EthereumAddress, amount: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 32 | func transferFrom(contractAddress: EthereumAddress , sender: EthereumAddress, recipient: EthereumAddress, amount: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 33 | } 34 | 35 | open class IERC20: IERC20Protocol { 36 | let client: EthereumClientProtocol 37 | 38 | required public init(client: EthereumClientProtocol) { 39 | self.client = client 40 | } 41 | 42 | public func _decimals(contractAddress: EthereumAddress ) async throws -> BigUInt { 43 | let function = IERC20Functions._decimals(contract: contractAddress ) 44 | let data = try await function.call(withClient: client, responseType: IERC20Responses._decimalsResponse.self) 45 | return data.value 46 | } 47 | public func _name(contractAddress: EthereumAddress ) async throws -> String { 48 | let function = IERC20Functions._name(contract: contractAddress ) 49 | let data = try await function.call(withClient: client, responseType: IERC20Responses._nameResponse.self) 50 | return data.value 51 | } 52 | public func _symbol(contractAddress: EthereumAddress ) async throws -> String { 53 | let function = IERC20Functions._symbol(contract: contractAddress ) 54 | let data = try await function.call(withClient: client, responseType: IERC20Responses._symbolResponse.self) 55 | return data.value 56 | } 57 | public func allowance(contractAddress: EthereumAddress , owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt { 58 | let function = IERC20Functions.allowance(contract: contractAddress , owner: owner, spender: spender) 59 | let data = try await function.call(withClient: client, responseType: IERC20Responses.allowanceResponse.self) 60 | return data.value 61 | } 62 | public func approve(contractAddress: EthereumAddress , spender: EthereumAddress, amount: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 63 | let tryCall = IERC20Functions.approve(contract: contractAddress, from: from, gasPrice: gasPrice, spender: spender, amount: amount) 64 | let subdata = try tryCall.transaction() 65 | let gas = try await client.eth_estimateGas(subdata) 66 | let function = IERC20Functions.approve(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, spender: spender, amount: amount) 67 | let data = try function.transaction() 68 | return data 69 | } 70 | public func balanceOf(contractAddress: EthereumAddress , account: EthereumAddress) async throws -> BigUInt { 71 | let function = IERC20Functions.balanceOf(contract: contractAddress , account: account) 72 | let data = try await function.call(withClient: client, responseType: IERC20Responses.balanceOfResponse.self) 73 | return data.value 74 | } 75 | public func burn(contractAddress: EthereumAddress , amount: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 76 | let tryCall = IERC20Functions.burn(contract: contractAddress, from: from, gasPrice: gasPrice, amount: amount) 77 | let subdata = try tryCall.transaction() 78 | let gas = try await client.eth_estimateGas(subdata) 79 | let function = IERC20Functions.burn(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amount: amount) 80 | let data = try function.transaction() 81 | return data 82 | } 83 | public func decimals(contractAddress: EthereumAddress ) async throws -> BigUInt { 84 | let function = IERC20Functions.decimals(contract: contractAddress ) 85 | let data = try await function.call(withClient: client, responseType: IERC20Responses.decimalsResponse.self) 86 | return data.value 87 | } 88 | public func decreaseAllowance(contractAddress: EthereumAddress , spender: EthereumAddress, subtractedValue: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 89 | let tryCall = IERC20Functions.decreaseAllowance(contract: contractAddress, from: from, gasPrice: gasPrice, spender: spender, subtractedValue: subtractedValue) 90 | let subdata = try tryCall.transaction() 91 | let gas = try await client.eth_estimateGas(subdata) 92 | let function = IERC20Functions.decreaseAllowance(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, spender: spender, subtractedValue: subtractedValue) 93 | let data = try function.transaction() 94 | return data 95 | } 96 | public func getOwner(contractAddress: EthereumAddress ) async throws -> EthereumAddress { 97 | let function = IERC20Functions.getOwner(contract: contractAddress ) 98 | let data = try await function.call(withClient: client, responseType: IERC20Responses.getOwnerResponse.self) 99 | return data.value 100 | } 101 | public func increaseAllowance(contractAddress: EthereumAddress , spender: EthereumAddress, addedValue: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 102 | let tryCall = IERC20Functions.increaseAllowance(contract: contractAddress, from: from, gasPrice: gasPrice, spender: spender, addedValue: addedValue) 103 | let subdata = try tryCall.transaction() 104 | let gas = try await client.eth_estimateGas(subdata) 105 | let function = IERC20Functions.increaseAllowance(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, spender: spender, addedValue: addedValue) 106 | let data = try function.transaction() 107 | return data 108 | } 109 | public func mint(contractAddress: EthereumAddress , amount: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 110 | let tryCall = IERC20Functions.mint(contract: contractAddress, from: from, gasPrice: gasPrice, amount: amount) 111 | let subdata = try tryCall.transaction() 112 | let gas = try await client.eth_estimateGas(subdata) 113 | let function = IERC20Functions.mint(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amount: amount) 114 | let data = try function.transaction() 115 | return data 116 | } 117 | public func name(contractAddress: EthereumAddress ) async throws -> String { 118 | let function = IERC20Functions.name(contract: contractAddress ) 119 | let data = try await function.call(withClient: client, responseType: IERC20Responses.nameResponse.self) 120 | return data.value 121 | } 122 | public func owner(contractAddress: EthereumAddress ) async throws -> EthereumAddress { 123 | let function = IERC20Functions.owner(contract: contractAddress ) 124 | let data = try await function.call(withClient: client, responseType: IERC20Responses.ownerResponse.self) 125 | return data.value 126 | } 127 | public func symbol(contractAddress: EthereumAddress ) async throws -> String { 128 | let function = IERC20Functions.symbol(contract: contractAddress ) 129 | let data = try await function.call(withClient: client, responseType: IERC20Responses.symbolResponse.self) 130 | return data.value 131 | } 132 | public func totalSupply(contractAddress: EthereumAddress ) async throws -> BigUInt { 133 | let function = IERC20Functions.totalSupply(contract: contractAddress ) 134 | let data = try await function.call(withClient: client, responseType: IERC20Responses.totalSupplyResponse.self) 135 | return data.value 136 | } 137 | public func transfer(contractAddress: EthereumAddress , recipient: EthereumAddress, amount: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 138 | let tryCall = IERC20Functions.transfer(contract: contractAddress, from: from, gasPrice: gasPrice, recipient: recipient, amount: amount) 139 | let subdata = try tryCall.transaction() 140 | let gas = try await client.eth_estimateGas(subdata) 141 | let function = IERC20Functions.transfer(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, recipient: recipient, amount: amount) 142 | let data = try function.transaction() 143 | return data 144 | } 145 | public func transferFrom(contractAddress: EthereumAddress , sender: EthereumAddress, recipient: EthereumAddress, amount: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 146 | let tryCall = IERC20Functions.transferFrom(contract: contractAddress, from: from, gasPrice: gasPrice, sender: sender, recipient: recipient, amount: amount) 147 | let subdata = try tryCall.transaction() 148 | let gas = try await client.eth_estimateGas(subdata) 149 | let function = IERC20Functions.transferFrom(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, sender: sender, recipient: recipient, amount: amount) 150 | let data = try function.transaction() 151 | return data 152 | } 153 | 154 | } 155 | open class IERC20Contract { 156 | var IERC20Call: IERC20? 157 | var client: EthereumClientProtocol 158 | var contract: web3.EthereumAddress 159 | 160 | init(contract: String, client: EthereumClientProtocol) { 161 | self.contract = EthereumAddress(contract) 162 | self.client = client 163 | self.IERC20Call = IERC20(client: client) 164 | } 165 | public func _decimals() async throws -> BigUInt{ 166 | return try await (IERC20Call?._decimals(contractAddress: contract))! 167 | } 168 | 169 | public func _name() async throws -> String{ 170 | return try await (IERC20Call?._name(contractAddress: contract))! 171 | } 172 | 173 | public func _symbol() async throws -> String{ 174 | return try await (IERC20Call?._symbol(contractAddress: contract))! 175 | } 176 | 177 | public func allowance(owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt{ 178 | return try await (IERC20Call?.allowance(contractAddress: contract, owner: owner, spender: spender))! 179 | } 180 | 181 | 182 | public func approve(spender: EthereumAddress,amount: BigUInt, account: EthereumAccount) async throws -> String{ 183 | let gasPrice = try await client.eth_gasPrice() 184 | let transaction = try await (IERC20Call?.approve(contractAddress:contract,spender: spender,amount: amount, from: account.address, gasPrice: gasPrice))! 185 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 186 | return txHash 187 | } 188 | 189 | public func balanceOf(account: EthereumAddress) async throws -> BigUInt{ 190 | return try await (IERC20Call?.balanceOf(contractAddress: contract, account: account))! 191 | } 192 | 193 | 194 | public func burn(amount: BigUInt, account: EthereumAccount) async throws -> String{ 195 | let gasPrice = try await client.eth_gasPrice() 196 | let transaction = try await (IERC20Call?.burn(contractAddress:contract,amount: amount, from: account.address, gasPrice: gasPrice))! 197 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 198 | return txHash 199 | } 200 | 201 | public func decimals() async throws -> BigUInt{ 202 | return try await (IERC20Call?.decimals(contractAddress: contract))! 203 | } 204 | 205 | 206 | public func decreaseAllowance(spender: EthereumAddress,subtractedValue: BigUInt, account: EthereumAccount) async throws -> String{ 207 | let gasPrice = try await client.eth_gasPrice() 208 | let transaction = try await (IERC20Call?.decreaseAllowance(contractAddress:contract,spender: spender,subtractedValue: subtractedValue, from: account.address, gasPrice: gasPrice))! 209 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 210 | return txHash 211 | } 212 | 213 | public func getOwner() async throws -> EthereumAddress{ 214 | return try await (IERC20Call?.getOwner(contractAddress: contract))! 215 | } 216 | 217 | 218 | public func increaseAllowance(spender: EthereumAddress,addedValue: BigUInt, account: EthereumAccount) async throws -> String{ 219 | let gasPrice = try await client.eth_gasPrice() 220 | let transaction = try await (IERC20Call?.increaseAllowance(contractAddress:contract,spender: spender,addedValue: addedValue, from: account.address, gasPrice: gasPrice))! 221 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 222 | return txHash 223 | } 224 | 225 | 226 | public func mint(amount: BigUInt, account: EthereumAccount) async throws -> String{ 227 | let gasPrice = try await client.eth_gasPrice() 228 | let transaction = try await (IERC20Call?.mint(contractAddress:contract,amount: amount, from: account.address, gasPrice: gasPrice))! 229 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 230 | return txHash 231 | } 232 | 233 | public func name() async throws -> String{ 234 | return try await (IERC20Call?.name(contractAddress: contract))! 235 | } 236 | 237 | public func owner() async throws -> EthereumAddress{ 238 | return try await (IERC20Call?.owner(contractAddress: contract))! 239 | } 240 | 241 | public func symbol() async throws -> String{ 242 | return try await (IERC20Call?.symbol(contractAddress: contract))! 243 | } 244 | 245 | public func totalSupply() async throws -> BigUInt{ 246 | return try await (IERC20Call?.totalSupply(contractAddress: contract))! 247 | } 248 | 249 | 250 | public func transfer(recipient: EthereumAddress,amount: BigUInt, account: EthereumAccount) async throws -> String{ 251 | let gasPrice = try await client.eth_gasPrice() 252 | let transaction = try await (IERC20Call?.transfer(contractAddress:contract,recipient: recipient,amount: amount, from: account.address, gasPrice: gasPrice))! 253 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 254 | return txHash 255 | } 256 | 257 | 258 | public func transferFrom(sender: EthereumAddress,recipient: EthereumAddress,amount: BigUInt, account: EthereumAccount) async throws -> String{ 259 | let gasPrice = try await client.eth_gasPrice() 260 | let transaction = try await (IERC20Call?.transferFrom(contractAddress:contract,sender: sender,recipient: recipient,amount: amount, from: account.address, gasPrice: gasPrice))! 261 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 262 | return txHash 263 | } 264 | 265 | 266 | } 267 | extension IERC20 { 268 | public func _decimals(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 269 | Task { 270 | do { 271 | let _decimals = try await _decimals(contractAddress: contractAddress ) 272 | completionHandler(.success(_decimals)) 273 | } catch { 274 | completionHandler(.failure(error)) 275 | } 276 | } 277 | } 278 | public func _name(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 279 | Task { 280 | do { 281 | let _name = try await _name(contractAddress: contractAddress ) 282 | completionHandler(.success(_name)) 283 | } catch { 284 | completionHandler(.failure(error)) 285 | } 286 | } 287 | } 288 | public func _symbol(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 289 | Task { 290 | do { 291 | let _symbol = try await _symbol(contractAddress: contractAddress ) 292 | completionHandler(.success(_symbol)) 293 | } catch { 294 | completionHandler(.failure(error)) 295 | } 296 | } 297 | } 298 | public func allowance(contractAddress: EthereumAddress, owner: EthereumAddress, spender: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 299 | Task { 300 | do { 301 | let allowance = try await allowance(contractAddress: contractAddress , owner: owner, spender: spender) 302 | completionHandler(.success(allowance)) 303 | } catch { 304 | completionHandler(.failure(error)) 305 | } 306 | } 307 | } 308 | public func balanceOf(contractAddress: EthereumAddress, account: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 309 | Task { 310 | do { 311 | let balanceOf = try await balanceOf(contractAddress: contractAddress , account: account) 312 | completionHandler(.success(balanceOf)) 313 | } catch { 314 | completionHandler(.failure(error)) 315 | } 316 | } 317 | } 318 | public func decimals(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 319 | Task { 320 | do { 321 | let decimals = try await decimals(contractAddress: contractAddress ) 322 | completionHandler(.success(decimals)) 323 | } catch { 324 | completionHandler(.failure(error)) 325 | } 326 | } 327 | } 328 | public func getOwner(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 329 | Task { 330 | do { 331 | let getOwner = try await getOwner(contractAddress: contractAddress ) 332 | completionHandler(.success(getOwner)) 333 | } catch { 334 | completionHandler(.failure(error)) 335 | } 336 | } 337 | } 338 | public func name(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 339 | Task { 340 | do { 341 | let name = try await name(contractAddress: contractAddress ) 342 | completionHandler(.success(name)) 343 | } catch { 344 | completionHandler(.failure(error)) 345 | } 346 | } 347 | } 348 | public func owner(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 349 | Task { 350 | do { 351 | let owner = try await owner(contractAddress: contractAddress ) 352 | completionHandler(.success(owner)) 353 | } catch { 354 | completionHandler(.failure(error)) 355 | } 356 | } 357 | } 358 | public func symbol(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 359 | Task { 360 | do { 361 | let symbol = try await symbol(contractAddress: contractAddress ) 362 | completionHandler(.success(symbol)) 363 | } catch { 364 | completionHandler(.failure(error)) 365 | } 366 | } 367 | } 368 | public func totalSupply(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 369 | Task { 370 | do { 371 | let totalSupply = try await totalSupply(contractAddress: contractAddress ) 372 | completionHandler(.success(totalSupply)) 373 | } catch { 374 | completionHandler(.failure(error)) 375 | } 376 | } 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /PancakeSwap.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "_factory", 7 | "type": "address" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "_WETH", 12 | "type": "address" 13 | } 14 | ], 15 | "stateMutability": "nonpayable", 16 | "type": "constructor" 17 | }, 18 | { 19 | "inputs": [], 20 | "name": "WETH", 21 | "outputs": [ 22 | { 23 | "internalType": "address", 24 | "name": "", 25 | "type": "address" 26 | } 27 | ], 28 | "stateMutability": "view", 29 | "type": "function" 30 | }, 31 | { 32 | "inputs": [ 33 | { 34 | "internalType": "address", 35 | "name": "tokenA", 36 | "type": "address" 37 | }, 38 | { 39 | "internalType": "address", 40 | "name": "tokenB", 41 | "type": "address" 42 | }, 43 | { 44 | "internalType": "uint256", 45 | "name": "amountADesired", 46 | "type": "uint256" 47 | }, 48 | { 49 | "internalType": "uint256", 50 | "name": "amountBDesired", 51 | "type": "uint256" 52 | }, 53 | { 54 | "internalType": "uint256", 55 | "name": "amountAMin", 56 | "type": "uint256" 57 | }, 58 | { 59 | "internalType": "uint256", 60 | "name": "amountBMin", 61 | "type": "uint256" 62 | }, 63 | { 64 | "internalType": "address", 65 | "name": "to", 66 | "type": "address" 67 | }, 68 | { 69 | "internalType": "uint256", 70 | "name": "deadline", 71 | "type": "uint256" 72 | } 73 | ], 74 | "name": "addLiquidity", 75 | "outputs": [ 76 | { 77 | "internalType": "uint256", 78 | "name": "amountA", 79 | "type": "uint256" 80 | }, 81 | { 82 | "internalType": "uint256", 83 | "name": "amountB", 84 | "type": "uint256" 85 | }, 86 | { 87 | "internalType": "uint256", 88 | "name": "liquidity", 89 | "type": "uint256" 90 | } 91 | ], 92 | "stateMutability": "nonpayable", 93 | "type": "function" 94 | }, 95 | { 96 | "inputs": [ 97 | { 98 | "internalType": "address", 99 | "name": "token", 100 | "type": "address" 101 | }, 102 | { 103 | "internalType": "uint256", 104 | "name": "amountTokenDesired", 105 | "type": "uint256" 106 | }, 107 | { 108 | "internalType": "uint256", 109 | "name": "amountTokenMin", 110 | "type": "uint256" 111 | }, 112 | { 113 | "internalType": "uint256", 114 | "name": "amountETHMin", 115 | "type": "uint256" 116 | }, 117 | { 118 | "internalType": "address", 119 | "name": "to", 120 | "type": "address" 121 | }, 122 | { 123 | "internalType": "uint256", 124 | "name": "deadline", 125 | "type": "uint256" 126 | } 127 | ], 128 | "name": "addLiquidityETH", 129 | "outputs": [ 130 | { 131 | "internalType": "uint256", 132 | "name": "amountToken", 133 | "type": "uint256" 134 | }, 135 | { 136 | "internalType": "uint256", 137 | "name": "amountETH", 138 | "type": "uint256" 139 | }, 140 | { 141 | "internalType": "uint256", 142 | "name": "liquidity", 143 | "type": "uint256" 144 | } 145 | ], 146 | "stateMutability": "payable", 147 | "type": "function" 148 | }, 149 | { 150 | "inputs": [], 151 | "name": "factory", 152 | "outputs": [ 153 | { 154 | "internalType": "address", 155 | "name": "", 156 | "type": "address" 157 | } 158 | ], 159 | "stateMutability": "view", 160 | "type": "function" 161 | }, 162 | { 163 | "inputs": [ 164 | { 165 | "internalType": "uint256", 166 | "name": "amountOut", 167 | "type": "uint256" 168 | }, 169 | { 170 | "internalType": "uint256", 171 | "name": "reserveIn", 172 | "type": "uint256" 173 | }, 174 | { 175 | "internalType": "uint256", 176 | "name": "reserveOut", 177 | "type": "uint256" 178 | } 179 | ], 180 | "name": "getAmountIn", 181 | "outputs": [ 182 | { 183 | "internalType": "uint256", 184 | "name": "amountIn", 185 | "type": "uint256" 186 | } 187 | ], 188 | "stateMutability": "pure", 189 | "type": "function" 190 | }, 191 | { 192 | "inputs": [ 193 | { 194 | "internalType": "uint256", 195 | "name": "amountIn", 196 | "type": "uint256" 197 | }, 198 | { 199 | "internalType": "uint256", 200 | "name": "reserveIn", 201 | "type": "uint256" 202 | }, 203 | { 204 | "internalType": "uint256", 205 | "name": "reserveOut", 206 | "type": "uint256" 207 | } 208 | ], 209 | "name": "getAmountOut", 210 | "outputs": [ 211 | { 212 | "internalType": "uint256", 213 | "name": "amountOut", 214 | "type": "uint256" 215 | } 216 | ], 217 | "stateMutability": "pure", 218 | "type": "function" 219 | }, 220 | { 221 | "inputs": [ 222 | { 223 | "internalType": "uint256", 224 | "name": "amountOut", 225 | "type": "uint256" 226 | }, 227 | { 228 | "internalType": "address[]", 229 | "name": "path", 230 | "type": "address[]" 231 | } 232 | ], 233 | "name": "getAmountsIn", 234 | "outputs": [ 235 | { 236 | "internalType": "uint256[]", 237 | "name": "amounts", 238 | "type": "uint256[]" 239 | } 240 | ], 241 | "stateMutability": "view", 242 | "type": "function" 243 | }, 244 | { 245 | "inputs": [ 246 | { 247 | "internalType": "uint256", 248 | "name": "amountIn", 249 | "type": "uint256" 250 | }, 251 | { 252 | "internalType": "address[]", 253 | "name": "path", 254 | "type": "address[]" 255 | } 256 | ], 257 | "name": "getAmountsOut", 258 | "outputs": [ 259 | { 260 | "internalType": "uint256[]", 261 | "name": "amounts", 262 | "type": "uint256[]" 263 | } 264 | ], 265 | "stateMutability": "view", 266 | "type": "function" 267 | }, 268 | { 269 | "inputs": [ 270 | { 271 | "internalType": "uint256", 272 | "name": "amountA", 273 | "type": "uint256" 274 | }, 275 | { 276 | "internalType": "uint256", 277 | "name": "reserveA", 278 | "type": "uint256" 279 | }, 280 | { 281 | "internalType": "uint256", 282 | "name": "reserveB", 283 | "type": "uint256" 284 | } 285 | ], 286 | "name": "quote", 287 | "outputs": [ 288 | { 289 | "internalType": "uint256", 290 | "name": "amountB", 291 | "type": "uint256" 292 | } 293 | ], 294 | "stateMutability": "pure", 295 | "type": "function" 296 | }, 297 | { 298 | "inputs": [ 299 | { 300 | "internalType": "address", 301 | "name": "tokenA", 302 | "type": "address" 303 | }, 304 | { 305 | "internalType": "address", 306 | "name": "tokenB", 307 | "type": "address" 308 | }, 309 | { 310 | "internalType": "uint256", 311 | "name": "liquidity", 312 | "type": "uint256" 313 | }, 314 | { 315 | "internalType": "uint256", 316 | "name": "amountAMin", 317 | "type": "uint256" 318 | }, 319 | { 320 | "internalType": "uint256", 321 | "name": "amountBMin", 322 | "type": "uint256" 323 | }, 324 | { 325 | "internalType": "address", 326 | "name": "to", 327 | "type": "address" 328 | }, 329 | { 330 | "internalType": "uint256", 331 | "name": "deadline", 332 | "type": "uint256" 333 | } 334 | ], 335 | "name": "removeLiquidity", 336 | "outputs": [ 337 | { 338 | "internalType": "uint256", 339 | "name": "amountA", 340 | "type": "uint256" 341 | }, 342 | { 343 | "internalType": "uint256", 344 | "name": "amountB", 345 | "type": "uint256" 346 | } 347 | ], 348 | "stateMutability": "nonpayable", 349 | "type": "function" 350 | }, 351 | { 352 | "inputs": [ 353 | { 354 | "internalType": "address", 355 | "name": "token", 356 | "type": "address" 357 | }, 358 | { 359 | "internalType": "uint256", 360 | "name": "liquidity", 361 | "type": "uint256" 362 | }, 363 | { 364 | "internalType": "uint256", 365 | "name": "amountTokenMin", 366 | "type": "uint256" 367 | }, 368 | { 369 | "internalType": "uint256", 370 | "name": "amountETHMin", 371 | "type": "uint256" 372 | }, 373 | { 374 | "internalType": "address", 375 | "name": "to", 376 | "type": "address" 377 | }, 378 | { 379 | "internalType": "uint256", 380 | "name": "deadline", 381 | "type": "uint256" 382 | } 383 | ], 384 | "name": "removeLiquidityETH", 385 | "outputs": [ 386 | { 387 | "internalType": "uint256", 388 | "name": "amountToken", 389 | "type": "uint256" 390 | }, 391 | { 392 | "internalType": "uint256", 393 | "name": "amountETH", 394 | "type": "uint256" 395 | } 396 | ], 397 | "stateMutability": "nonpayable", 398 | "type": "function" 399 | }, 400 | { 401 | "inputs": [ 402 | { 403 | "internalType": "address", 404 | "name": "token", 405 | "type": "address" 406 | }, 407 | { 408 | "internalType": "uint256", 409 | "name": "liquidity", 410 | "type": "uint256" 411 | }, 412 | { 413 | "internalType": "uint256", 414 | "name": "amountTokenMin", 415 | "type": "uint256" 416 | }, 417 | { 418 | "internalType": "uint256", 419 | "name": "amountETHMin", 420 | "type": "uint256" 421 | }, 422 | { 423 | "internalType": "address", 424 | "name": "to", 425 | "type": "address" 426 | }, 427 | { 428 | "internalType": "uint256", 429 | "name": "deadline", 430 | "type": "uint256" 431 | } 432 | ], 433 | "name": "removeLiquidityETHSupportingFeeOnTransferTokens", 434 | "outputs": [ 435 | { 436 | "internalType": "uint256", 437 | "name": "amountETH", 438 | "type": "uint256" 439 | } 440 | ], 441 | "stateMutability": "nonpayable", 442 | "type": "function" 443 | }, 444 | { 445 | "inputs": [ 446 | { 447 | "internalType": "address", 448 | "name": "token", 449 | "type": "address" 450 | }, 451 | { 452 | "internalType": "uint256", 453 | "name": "liquidity", 454 | "type": "uint256" 455 | }, 456 | { 457 | "internalType": "uint256", 458 | "name": "amountTokenMin", 459 | "type": "uint256" 460 | }, 461 | { 462 | "internalType": "uint256", 463 | "name": "amountETHMin", 464 | "type": "uint256" 465 | }, 466 | { 467 | "internalType": "address", 468 | "name": "to", 469 | "type": "address" 470 | }, 471 | { 472 | "internalType": "uint256", 473 | "name": "deadline", 474 | "type": "uint256" 475 | }, 476 | { 477 | "internalType": "bool", 478 | "name": "approveMax", 479 | "type": "bool" 480 | }, 481 | { 482 | "internalType": "uint8", 483 | "name": "v", 484 | "type": "uint8" 485 | }, 486 | { 487 | "internalType": "bytes32", 488 | "name": "r", 489 | "type": "bytes32" 490 | }, 491 | { 492 | "internalType": "bytes32", 493 | "name": "s", 494 | "type": "bytes32" 495 | } 496 | ], 497 | "name": "removeLiquidityETHWithPermit", 498 | "outputs": [ 499 | { 500 | "internalType": "uint256", 501 | "name": "amountToken", 502 | "type": "uint256" 503 | }, 504 | { 505 | "internalType": "uint256", 506 | "name": "amountETH", 507 | "type": "uint256" 508 | } 509 | ], 510 | "stateMutability": "nonpayable", 511 | "type": "function" 512 | }, 513 | { 514 | "inputs": [ 515 | { 516 | "internalType": "address", 517 | "name": "token", 518 | "type": "address" 519 | }, 520 | { 521 | "internalType": "uint256", 522 | "name": "liquidity", 523 | "type": "uint256" 524 | }, 525 | { 526 | "internalType": "uint256", 527 | "name": "amountTokenMin", 528 | "type": "uint256" 529 | }, 530 | { 531 | "internalType": "uint256", 532 | "name": "amountETHMin", 533 | "type": "uint256" 534 | }, 535 | { 536 | "internalType": "address", 537 | "name": "to", 538 | "type": "address" 539 | }, 540 | { 541 | "internalType": "uint256", 542 | "name": "deadline", 543 | "type": "uint256" 544 | }, 545 | { 546 | "internalType": "bool", 547 | "name": "approveMax", 548 | "type": "bool" 549 | }, 550 | { 551 | "internalType": "uint8", 552 | "name": "v", 553 | "type": "uint8" 554 | }, 555 | { 556 | "internalType": "bytes32", 557 | "name": "r", 558 | "type": "bytes32" 559 | }, 560 | { 561 | "internalType": "bytes32", 562 | "name": "s", 563 | "type": "bytes32" 564 | } 565 | ], 566 | "name": "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens", 567 | "outputs": [ 568 | { 569 | "internalType": "uint256", 570 | "name": "amountETH", 571 | "type": "uint256" 572 | } 573 | ], 574 | "stateMutability": "nonpayable", 575 | "type": "function" 576 | }, 577 | { 578 | "inputs": [ 579 | { 580 | "internalType": "address", 581 | "name": "tokenA", 582 | "type": "address" 583 | }, 584 | { 585 | "internalType": "address", 586 | "name": "tokenB", 587 | "type": "address" 588 | }, 589 | { 590 | "internalType": "uint256", 591 | "name": "liquidity", 592 | "type": "uint256" 593 | }, 594 | { 595 | "internalType": "uint256", 596 | "name": "amountAMin", 597 | "type": "uint256" 598 | }, 599 | { 600 | "internalType": "uint256", 601 | "name": "amountBMin", 602 | "type": "uint256" 603 | }, 604 | { 605 | "internalType": "address", 606 | "name": "to", 607 | "type": "address" 608 | }, 609 | { 610 | "internalType": "uint256", 611 | "name": "deadline", 612 | "type": "uint256" 613 | }, 614 | { 615 | "internalType": "bool", 616 | "name": "approveMax", 617 | "type": "bool" 618 | }, 619 | { 620 | "internalType": "uint8", 621 | "name": "v", 622 | "type": "uint8" 623 | }, 624 | { 625 | "internalType": "bytes32", 626 | "name": "r", 627 | "type": "bytes32" 628 | }, 629 | { 630 | "internalType": "bytes32", 631 | "name": "s", 632 | "type": "bytes32" 633 | } 634 | ], 635 | "name": "removeLiquidityWithPermit", 636 | "outputs": [ 637 | { 638 | "internalType": "uint256", 639 | "name": "amountA", 640 | "type": "uint256" 641 | }, 642 | { 643 | "internalType": "uint256", 644 | "name": "amountB", 645 | "type": "uint256" 646 | } 647 | ], 648 | "stateMutability": "nonpayable", 649 | "type": "function" 650 | }, 651 | { 652 | "inputs": [ 653 | { 654 | "internalType": "uint256", 655 | "name": "amountOut", 656 | "type": "uint256" 657 | }, 658 | { 659 | "internalType": "address[]", 660 | "name": "path", 661 | "type": "address[]" 662 | }, 663 | { 664 | "internalType": "address", 665 | "name": "to", 666 | "type": "address" 667 | }, 668 | { 669 | "internalType": "uint256", 670 | "name": "deadline", 671 | "type": "uint256" 672 | } 673 | ], 674 | "name": "swapETHForExactTokens", 675 | "outputs": [ 676 | { 677 | "internalType": "uint256[]", 678 | "name": "amounts", 679 | "type": "uint256[]" 680 | } 681 | ], 682 | "stateMutability": "payable", 683 | "type": "function" 684 | }, 685 | { 686 | "inputs": [ 687 | { 688 | "internalType": "uint256", 689 | "name": "amountOutMin", 690 | "type": "uint256" 691 | }, 692 | { 693 | "internalType": "address[]", 694 | "name": "path", 695 | "type": "address[]" 696 | }, 697 | { 698 | "internalType": "address", 699 | "name": "to", 700 | "type": "address" 701 | }, 702 | { 703 | "internalType": "uint256", 704 | "name": "deadline", 705 | "type": "uint256" 706 | } 707 | ], 708 | "name": "swapExactETHForTokens", 709 | "outputs": [ 710 | { 711 | "internalType": "uint256[]", 712 | "name": "amounts", 713 | "type": "uint256[]" 714 | } 715 | ], 716 | "stateMutability": "payable", 717 | "type": "function" 718 | }, 719 | { 720 | "inputs": [ 721 | { 722 | "internalType": "uint256", 723 | "name": "amountOutMin", 724 | "type": "uint256" 725 | }, 726 | { 727 | "internalType": "address[]", 728 | "name": "path", 729 | "type": "address[]" 730 | }, 731 | { 732 | "internalType": "address", 733 | "name": "to", 734 | "type": "address" 735 | }, 736 | { 737 | "internalType": "uint256", 738 | "name": "deadline", 739 | "type": "uint256" 740 | } 741 | ], 742 | "name": "swapExactETHForTokensSupportingFeeOnTransferTokens", 743 | "outputs": [], 744 | "stateMutability": "payable", 745 | "type": "function" 746 | }, 747 | { 748 | "inputs": [ 749 | { 750 | "internalType": "uint256", 751 | "name": "amountIn", 752 | "type": "uint256" 753 | }, 754 | { 755 | "internalType": "uint256", 756 | "name": "amountOutMin", 757 | "type": "uint256" 758 | }, 759 | { 760 | "internalType": "address[]", 761 | "name": "path", 762 | "type": "address[]" 763 | }, 764 | { 765 | "internalType": "address", 766 | "name": "to", 767 | "type": "address" 768 | }, 769 | { 770 | "internalType": "uint256", 771 | "name": "deadline", 772 | "type": "uint256" 773 | } 774 | ], 775 | "name": "swapExactTokensForETH", 776 | "outputs": [ 777 | { 778 | "internalType": "uint256[]", 779 | "name": "amounts", 780 | "type": "uint256[]" 781 | } 782 | ], 783 | "stateMutability": "nonpayable", 784 | "type": "function" 785 | }, 786 | { 787 | "inputs": [ 788 | { 789 | "internalType": "uint256", 790 | "name": "amountIn", 791 | "type": "uint256" 792 | }, 793 | { 794 | "internalType": "uint256", 795 | "name": "amountOutMin", 796 | "type": "uint256" 797 | }, 798 | { 799 | "internalType": "address[]", 800 | "name": "path", 801 | "type": "address[]" 802 | }, 803 | { 804 | "internalType": "address", 805 | "name": "to", 806 | "type": "address" 807 | }, 808 | { 809 | "internalType": "uint256", 810 | "name": "deadline", 811 | "type": "uint256" 812 | } 813 | ], 814 | "name": "swapExactTokensForETHSupportingFeeOnTransferTokens", 815 | "outputs": [], 816 | "stateMutability": "nonpayable", 817 | "type": "function" 818 | }, 819 | { 820 | "inputs": [ 821 | { 822 | "internalType": "uint256", 823 | "name": "amountIn", 824 | "type": "uint256" 825 | }, 826 | { 827 | "internalType": "uint256", 828 | "name": "amountOutMin", 829 | "type": "uint256" 830 | }, 831 | { 832 | "internalType": "address[]", 833 | "name": "path", 834 | "type": "address[]" 835 | }, 836 | { 837 | "internalType": "address", 838 | "name": "to", 839 | "type": "address" 840 | }, 841 | { 842 | "internalType": "uint256", 843 | "name": "deadline", 844 | "type": "uint256" 845 | } 846 | ], 847 | "name": "swapExactTokensForTokens", 848 | "outputs": [ 849 | { 850 | "internalType": "uint256[]", 851 | "name": "amounts", 852 | "type": "uint256[]" 853 | } 854 | ], 855 | "stateMutability": "nonpayable", 856 | "type": "function" 857 | }, 858 | { 859 | "inputs": [ 860 | { 861 | "internalType": "uint256", 862 | "name": "amountIn", 863 | "type": "uint256" 864 | }, 865 | { 866 | "internalType": "uint256", 867 | "name": "amountOutMin", 868 | "type": "uint256" 869 | }, 870 | { 871 | "internalType": "address[]", 872 | "name": "path", 873 | "type": "address[]" 874 | }, 875 | { 876 | "internalType": "address", 877 | "name": "to", 878 | "type": "address" 879 | }, 880 | { 881 | "internalType": "uint256", 882 | "name": "deadline", 883 | "type": "uint256" 884 | } 885 | ], 886 | "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens", 887 | "outputs": [], 888 | "stateMutability": "nonpayable", 889 | "type": "function" 890 | }, 891 | { 892 | "inputs": [ 893 | { 894 | "internalType": "uint256", 895 | "name": "amountOut", 896 | "type": "uint256" 897 | }, 898 | { 899 | "internalType": "uint256", 900 | "name": "amountInMax", 901 | "type": "uint256" 902 | }, 903 | { 904 | "internalType": "address[]", 905 | "name": "path", 906 | "type": "address[]" 907 | }, 908 | { 909 | "internalType": "address", 910 | "name": "to", 911 | "type": "address" 912 | }, 913 | { 914 | "internalType": "uint256", 915 | "name": "deadline", 916 | "type": "uint256" 917 | } 918 | ], 919 | "name": "swapTokensForExactETH", 920 | "outputs": [ 921 | { 922 | "internalType": "uint256[]", 923 | "name": "amounts", 924 | "type": "uint256[]" 925 | } 926 | ], 927 | "stateMutability": "nonpayable", 928 | "type": "function" 929 | }, 930 | { 931 | "inputs": [ 932 | { 933 | "internalType": "uint256", 934 | "name": "amountOut", 935 | "type": "uint256" 936 | }, 937 | { 938 | "internalType": "uint256", 939 | "name": "amountInMax", 940 | "type": "uint256" 941 | }, 942 | { 943 | "internalType": "address[]", 944 | "name": "path", 945 | "type": "address[]" 946 | }, 947 | { 948 | "internalType": "address", 949 | "name": "to", 950 | "type": "address" 951 | }, 952 | { 953 | "internalType": "uint256", 954 | "name": "deadline", 955 | "type": "uint256" 956 | } 957 | ], 958 | "name": "swapTokensForExactTokens", 959 | "outputs": [ 960 | { 961 | "internalType": "uint256[]", 962 | "name": "amounts", 963 | "type": "uint256[]" 964 | } 965 | ], 966 | "stateMutability": "nonpayable", 967 | "type": "function" 968 | }, 969 | { 970 | "stateMutability": "payable", 971 | "type": "receive" 972 | } 973 | ] -------------------------------------------------------------------------------- /PancakeSwap/PancakeSwap.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // swiftAbi 4 | // Don't change the files! this file is generated! 5 | // https://github.com/imanrep/ 6 | // 7 | 8 | import BigInt 9 | import Foundation 10 | import web3 11 | 12 | public protocol PancakeSwapProtocol { 13 | init(client: EthereumClientProtocol) 14 | 15 | func WETH(contractAddress: EthereumAddress ) async throws -> EthereumAddress 16 | func addLiquidity(contractAddress: EthereumAddress , tokenA: EthereumAddress, tokenB: EthereumAddress, amountADesired: BigUInt, amountBDesired: BigUInt, amountAMin: BigUInt, amountBMin: BigUInt, to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 17 | func addLiquidityETH(contractAddress: EthereumAddress , token: EthereumAddress, amountTokenDesired: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 18 | func factory(contractAddress: EthereumAddress ) async throws -> EthereumAddress 19 | func getAmountIn(contractAddress: EthereumAddress , amountOut: BigUInt, reserveIn: BigUInt, reserveOut: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 20 | func getAmountOut(contractAddress: EthereumAddress , amountIn: BigUInt, reserveIn: BigUInt, reserveOut: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 21 | func getAmountsIn(contractAddress: EthereumAddress , amountOut: BigUInt, path: [EthereumAddress] ) async throws -> [BigUInt] 22 | func getAmountsOut(contractAddress: EthereumAddress , amountIn: BigUInt, path: [EthereumAddress] ) async throws -> [BigUInt] 23 | func quote(contractAddress: EthereumAddress , amountA: BigUInt, reserveA: BigUInt, reserveB: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 24 | func removeLiquidity(contractAddress: EthereumAddress , tokenA: EthereumAddress, tokenB: EthereumAddress, liquidity: BigUInt, amountAMin: BigUInt, amountBMin: BigUInt, to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 25 | func removeLiquidityETH(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 26 | func removeLiquidityETHSupportingFeeOnTransferTokens(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 27 | func removeLiquidityETHWithPermit(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, approveMax: Bool, v: BigUInt, r: BigUInt, s: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 28 | func removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, approveMax: Bool, v: BigUInt, r: BigUInt, s: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 29 | func removeLiquidityWithPermit(contractAddress: EthereumAddress , tokenA: EthereumAddress, tokenB: EthereumAddress, liquidity: BigUInt, amountAMin: BigUInt, amountBMin: BigUInt, to: EthereumAddress, deadline: BigUInt, approveMax: Bool, v: BigUInt, r: BigUInt, s: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 30 | func swapETHForExactTokens(contractAddress: EthereumAddress , amountOut: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 31 | func swapExactETHForTokens(contractAddress: EthereumAddress , amountOutMin: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 32 | func swapExactTokensForETH(contractAddress: EthereumAddress , amountIn: BigUInt, amountOutMin: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 33 | func swapExactTokensForTokens(contractAddress: EthereumAddress , amountIn: BigUInt, amountOutMin: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 34 | func swapTokensForExactETH(contractAddress: EthereumAddress , amountOut: BigUInt, amountInMax: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 35 | func swapTokensForExactTokens(contractAddress: EthereumAddress , amountOut: BigUInt, amountInMax: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt ,from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction 36 | } 37 | 38 | open class PancakeSwap: PancakeSwapProtocol { 39 | let client: EthereumClientProtocol 40 | 41 | required public init(client: EthereumClientProtocol) { 42 | self.client = client 43 | } 44 | 45 | public func WETH(contractAddress: EthereumAddress ) async throws -> EthereumAddress { 46 | let function = PancakeSwapFunctions.WETH(contract: contractAddress ) 47 | let data = try await function.call(withClient: client, responseType: PancakeSwapResponses.WETHResponse.self) 48 | return data.value 49 | } 50 | public func addLiquidity(contractAddress: EthereumAddress , tokenA: EthereumAddress, tokenB: EthereumAddress, amountADesired: BigUInt, amountBDesired: BigUInt, amountAMin: BigUInt, amountBMin: BigUInt, to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 51 | let tryCall = PancakeSwapFunctions.addLiquidity(contract: contractAddress, from: from, gasPrice: gasPrice, tokenA: tokenA, tokenB: tokenB, amountADesired: amountADesired, amountBDesired: amountBDesired, amountAMin: amountAMin, amountBMin: amountBMin, to: to, deadline: deadline) 52 | let subdata = try tryCall.transaction() 53 | let gas = try await client.eth_estimateGas(subdata) 54 | let function = PancakeSwapFunctions.addLiquidity(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, tokenA: tokenA, tokenB: tokenB, amountADesired: amountADesired, amountBDesired: amountBDesired, amountAMin: amountAMin, amountBMin: amountBMin, to: to, deadline: deadline) 55 | let data = try function.transaction() 56 | return data 57 | } 58 | public func addLiquidityETH(contractAddress: EthereumAddress , token: EthereumAddress, amountTokenDesired: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 59 | let tryCall = PancakeSwapFunctions.addLiquidityETH(contract: contractAddress, from: from, gasPrice: gasPrice, token: token, amountTokenDesired: amountTokenDesired, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline) 60 | let subdata = try tryCall.transaction() 61 | let gas = try await client.eth_estimateGas(subdata) 62 | let function = PancakeSwapFunctions.addLiquidityETH(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, token: token, amountTokenDesired: amountTokenDesired, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline) 63 | let data = try function.transaction() 64 | return data 65 | } 66 | public func factory(contractAddress: EthereumAddress ) async throws -> EthereumAddress { 67 | let function = PancakeSwapFunctions.factory(contract: contractAddress ) 68 | let data = try await function.call(withClient: client, responseType: PancakeSwapResponses.factoryResponse.self) 69 | return data.value 70 | } 71 | public func getAmountIn(contractAddress: EthereumAddress , amountOut: BigUInt, reserveIn: BigUInt, reserveOut: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 72 | let tryCall = PancakeSwapFunctions.getAmountIn(contract: contractAddress, from: from, gasPrice: gasPrice, amountOut: amountOut, reserveIn: reserveIn, reserveOut: reserveOut) 73 | let subdata = try tryCall.transaction() 74 | let gas = try await client.eth_estimateGas(subdata) 75 | let function = PancakeSwapFunctions.getAmountIn(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountOut: amountOut, reserveIn: reserveIn, reserveOut: reserveOut) 76 | let data = try function.transaction() 77 | return data 78 | } 79 | public func getAmountOut(contractAddress: EthereumAddress , amountIn: BigUInt, reserveIn: BigUInt, reserveOut: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 80 | let tryCall = PancakeSwapFunctions.getAmountOut(contract: contractAddress, from: from, gasPrice: gasPrice, amountIn: amountIn, reserveIn: reserveIn, reserveOut: reserveOut) 81 | let subdata = try tryCall.transaction() 82 | let gas = try await client.eth_estimateGas(subdata) 83 | let function = PancakeSwapFunctions.getAmountOut(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountIn: amountIn, reserveIn: reserveIn, reserveOut: reserveOut) 84 | let data = try function.transaction() 85 | return data 86 | } 87 | public func getAmountsIn(contractAddress: EthereumAddress , amountOut: BigUInt, path: [EthereumAddress]) async throws -> [BigUInt] { 88 | let function = PancakeSwapFunctions.getAmountsIn(contract: contractAddress , amountOut: amountOut, path: path) 89 | let data = try await function.call(withClient: client, responseType: PancakeSwapResponses.getAmountsInResponse.self) 90 | return data.value 91 | } 92 | public func getAmountsOut(contractAddress: EthereumAddress , amountIn: BigUInt, path: [EthereumAddress]) async throws -> [BigUInt] { 93 | let function = PancakeSwapFunctions.getAmountsOut(contract: contractAddress , amountIn: amountIn, path: path) 94 | let data = try await function.call(withClient: client, responseType: PancakeSwapResponses.getAmountsOutResponse.self) 95 | return data.value 96 | } 97 | public func quote(contractAddress: EthereumAddress , amountA: BigUInt, reserveA: BigUInt, reserveB: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 98 | let tryCall = PancakeSwapFunctions.quote(contract: contractAddress, from: from, gasPrice: gasPrice, amountA: amountA, reserveA: reserveA, reserveB: reserveB) 99 | let subdata = try tryCall.transaction() 100 | let gas = try await client.eth_estimateGas(subdata) 101 | let function = PancakeSwapFunctions.quote(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountA: amountA, reserveA: reserveA, reserveB: reserveB) 102 | let data = try function.transaction() 103 | return data 104 | } 105 | public func removeLiquidity(contractAddress: EthereumAddress , tokenA: EthereumAddress, tokenB: EthereumAddress, liquidity: BigUInt, amountAMin: BigUInt, amountBMin: BigUInt, to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 106 | let tryCall = PancakeSwapFunctions.removeLiquidity(contract: contractAddress, from: from, gasPrice: gasPrice, tokenA: tokenA, tokenB: tokenB, liquidity: liquidity, amountAMin: amountAMin, amountBMin: amountBMin, to: to, deadline: deadline) 107 | let subdata = try tryCall.transaction() 108 | let gas = try await client.eth_estimateGas(subdata) 109 | let function = PancakeSwapFunctions.removeLiquidity(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, tokenA: tokenA, tokenB: tokenB, liquidity: liquidity, amountAMin: amountAMin, amountBMin: amountBMin, to: to, deadline: deadline) 110 | let data = try function.transaction() 111 | return data 112 | } 113 | public func removeLiquidityETH(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 114 | let tryCall = PancakeSwapFunctions.removeLiquidityETH(contract: contractAddress, from: from, gasPrice: gasPrice, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline) 115 | let subdata = try tryCall.transaction() 116 | let gas = try await client.eth_estimateGas(subdata) 117 | let function = PancakeSwapFunctions.removeLiquidityETH(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline) 118 | let data = try function.transaction() 119 | return data 120 | } 121 | public func removeLiquidityETHSupportingFeeOnTransferTokens(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 122 | let tryCall = PancakeSwapFunctions.removeLiquidityETHSupportingFeeOnTransferTokens(contract: contractAddress, from: from, gasPrice: gasPrice, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline) 123 | let subdata = try tryCall.transaction() 124 | let gas = try await client.eth_estimateGas(subdata) 125 | let function = PancakeSwapFunctions.removeLiquidityETHSupportingFeeOnTransferTokens(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline) 126 | let data = try function.transaction() 127 | return data 128 | } 129 | public func removeLiquidityETHWithPermit(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, approveMax: Bool, v: BigUInt, r: BigUInt, s: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 130 | let tryCall = PancakeSwapFunctions.removeLiquidityETHWithPermit(contract: contractAddress, from: from, gasPrice: gasPrice, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline, approveMax: approveMax, v: v, r: r, s: s) 131 | let subdata = try tryCall.transaction() 132 | let gas = try await client.eth_estimateGas(subdata) 133 | let function = PancakeSwapFunctions.removeLiquidityETHWithPermit(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline, approveMax: approveMax, v: v, r: r, s: s) 134 | let data = try function.transaction() 135 | return data 136 | } 137 | public func removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(contractAddress: EthereumAddress , token: EthereumAddress, liquidity: BigUInt, amountTokenMin: BigUInt, amountETHMin: BigUInt, to: EthereumAddress, deadline: BigUInt, approveMax: Bool, v: BigUInt, r: BigUInt, s: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 138 | let tryCall = PancakeSwapFunctions.removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(contract: contractAddress, from: from, gasPrice: gasPrice, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline, approveMax: approveMax, v: v, r: r, s: s) 139 | let subdata = try tryCall.transaction() 140 | let gas = try await client.eth_estimateGas(subdata) 141 | let function = PancakeSwapFunctions.removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, token: token, liquidity: liquidity, amountTokenMin: amountTokenMin, amountETHMin: amountETHMin, to: to, deadline: deadline, approveMax: approveMax, v: v, r: r, s: s) 142 | let data = try function.transaction() 143 | return data 144 | } 145 | public func removeLiquidityWithPermit(contractAddress: EthereumAddress , tokenA: EthereumAddress, tokenB: EthereumAddress, liquidity: BigUInt, amountAMin: BigUInt, amountBMin: BigUInt, to: EthereumAddress, deadline: BigUInt, approveMax: Bool, v: BigUInt, r: BigUInt, s: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 146 | let tryCall = PancakeSwapFunctions.removeLiquidityWithPermit(contract: contractAddress, from: from, gasPrice: gasPrice, tokenA: tokenA, tokenB: tokenB, liquidity: liquidity, amountAMin: amountAMin, amountBMin: amountBMin, to: to, deadline: deadline, approveMax: approveMax, v: v, r: r, s: s) 147 | let subdata = try tryCall.transaction() 148 | let gas = try await client.eth_estimateGas(subdata) 149 | let function = PancakeSwapFunctions.removeLiquidityWithPermit(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, tokenA: tokenA, tokenB: tokenB, liquidity: liquidity, amountAMin: amountAMin, amountBMin: amountBMin, to: to, deadline: deadline, approveMax: approveMax, v: v, r: r, s: s) 150 | let data = try function.transaction() 151 | return data 152 | } 153 | public func swapETHForExactTokens(contractAddress: EthereumAddress , amountOut: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 154 | let tryCall = PancakeSwapFunctions.swapETHForExactTokens(contract: contractAddress, from: from, gasPrice: gasPrice, amountOut: amountOut, path: path, to: to, deadline: deadline) 155 | let subdata = try tryCall.transaction() 156 | let gas = try await client.eth_estimateGas(subdata) 157 | let function = PancakeSwapFunctions.swapETHForExactTokens(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountOut: amountOut, path: path, to: to, deadline: deadline) 158 | let data = try function.transaction() 159 | return data 160 | } 161 | public func swapExactETHForTokens(contractAddress: EthereumAddress , amountOutMin: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 162 | let tryCall = PancakeSwapFunctions.swapExactETHForTokens(contract: contractAddress, from: from, gasPrice: gasPrice, amountOutMin: amountOutMin, path: path, to: to, deadline: deadline) 163 | let subdata = try tryCall.transaction() 164 | let gas = try await client.eth_estimateGas(subdata) 165 | let function = PancakeSwapFunctions.swapExactETHForTokens(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountOutMin: amountOutMin, path: path, to: to, deadline: deadline) 166 | let data = try function.transaction() 167 | return data 168 | } 169 | public func swapExactTokensForETH(contractAddress: EthereumAddress , amountIn: BigUInt, amountOutMin: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 170 | let tryCall = PancakeSwapFunctions.swapExactTokensForETH(contract: contractAddress, from: from, gasPrice: gasPrice, amountIn: amountIn, amountOutMin: amountOutMin, path: path, to: to, deadline: deadline) 171 | let subdata = try tryCall.transaction() 172 | let gas = try await client.eth_estimateGas(subdata) 173 | let function = PancakeSwapFunctions.swapExactTokensForETH(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountIn: amountIn, amountOutMin: amountOutMin, path: path, to: to, deadline: deadline) 174 | let data = try function.transaction() 175 | return data 176 | } 177 | public func swapExactTokensForTokens(contractAddress: EthereumAddress , amountIn: BigUInt, amountOutMin: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 178 | let tryCall = PancakeSwapFunctions.swapExactTokensForTokens(contract: contractAddress, from: from, gasPrice: gasPrice, amountIn: amountIn, amountOutMin: amountOutMin, path: path, to: to, deadline: deadline) 179 | let subdata = try tryCall.transaction() 180 | let gas = try await client.eth_estimateGas(subdata) 181 | let function = PancakeSwapFunctions.swapExactTokensForTokens(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountIn: amountIn, amountOutMin: amountOutMin, path: path, to: to, deadline: deadline) 182 | let data = try function.transaction() 183 | return data 184 | } 185 | public func swapTokensForExactETH(contractAddress: EthereumAddress , amountOut: BigUInt, amountInMax: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 186 | let tryCall = PancakeSwapFunctions.swapTokensForExactETH(contract: contractAddress, from: from, gasPrice: gasPrice, amountOut: amountOut, amountInMax: amountInMax, path: path, to: to, deadline: deadline) 187 | let subdata = try tryCall.transaction() 188 | let gas = try await client.eth_estimateGas(subdata) 189 | let function = PancakeSwapFunctions.swapTokensForExactETH(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountOut: amountOut, amountInMax: amountInMax, path: path, to: to, deadline: deadline) 190 | let data = try function.transaction() 191 | return data 192 | } 193 | public func swapTokensForExactTokens(contractAddress: EthereumAddress , amountOut: BigUInt, amountInMax: BigUInt, path: [EthereumAddress], to: EthereumAddress, deadline: BigUInt, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 194 | let tryCall = PancakeSwapFunctions.swapTokensForExactTokens(contract: contractAddress, from: from, gasPrice: gasPrice, amountOut: amountOut, amountInMax: amountInMax, path: path, to: to, deadline: deadline) 195 | let subdata = try tryCall.transaction() 196 | let gas = try await client.eth_estimateGas(subdata) 197 | let function = PancakeSwapFunctions.swapTokensForExactTokens(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas, amountOut: amountOut, amountInMax: amountInMax, path: path, to: to, deadline: deadline) 198 | let data = try function.transaction() 199 | return data 200 | } 201 | 202 | } 203 | open class PancakeSwapContract { 204 | var PancakeSwapCall: PancakeSwap? 205 | var client: EthereumClientProtocol 206 | var contract: web3.EthereumAddress 207 | 208 | init(contract: String, client: EthereumClientProtocol) { 209 | self.contract = EthereumAddress(contract) 210 | self.client = client 211 | self.PancakeSwapCall = PancakeSwap(client: client) 212 | } 213 | public func WETH() async throws -> EthereumAddress{ 214 | return try await (PancakeSwapCall?.WETH(contractAddress: contract))! 215 | } 216 | 217 | 218 | public func addLiquidity(tokenA: EthereumAddress,tokenB: EthereumAddress,amountADesired: BigUInt,amountBDesired: BigUInt,amountAMin: BigUInt,amountBMin: BigUInt,to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 219 | let gasPrice = try await client.eth_gasPrice() 220 | let transaction = try await (PancakeSwapCall?.addLiquidity(contractAddress:contract,tokenA: tokenA,tokenB: tokenB,amountADesired: amountADesired,amountBDesired: amountBDesired,amountAMin: amountAMin,amountBMin: amountBMin,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 221 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 222 | return txHash 223 | } 224 | 225 | 226 | public func addLiquidityETH(token: EthereumAddress,amountTokenDesired: BigUInt,amountTokenMin: BigUInt,amountETHMin: BigUInt,to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 227 | let gasPrice = try await client.eth_gasPrice() 228 | let transaction = try await (PancakeSwapCall?.addLiquidityETH(contractAddress:contract,token: token,amountTokenDesired: amountTokenDesired,amountTokenMin: amountTokenMin,amountETHMin: amountETHMin,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 229 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 230 | return txHash 231 | } 232 | 233 | public func factory() async throws -> EthereumAddress{ 234 | return try await (PancakeSwapCall?.factory(contractAddress: contract))! 235 | } 236 | 237 | 238 | public func getAmountIn(amountOut: BigUInt,reserveIn: BigUInt,reserveOut: BigUInt, account: EthereumAccount) async throws -> String{ 239 | let gasPrice = try await client.eth_gasPrice() 240 | let transaction = try await (PancakeSwapCall?.getAmountIn(contractAddress:contract,amountOut: amountOut,reserveIn: reserveIn,reserveOut: reserveOut, from: account.address, gasPrice: gasPrice))! 241 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 242 | return txHash 243 | } 244 | 245 | 246 | public func getAmountOut(amountIn: BigUInt,reserveIn: BigUInt,reserveOut: BigUInt, account: EthereumAccount) async throws -> String{ 247 | let gasPrice = try await client.eth_gasPrice() 248 | let transaction = try await (PancakeSwapCall?.getAmountOut(contractAddress:contract,amountIn: amountIn,reserveIn: reserveIn,reserveOut: reserveOut, from: account.address, gasPrice: gasPrice))! 249 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 250 | return txHash 251 | } 252 | 253 | public func getAmountsIn(amountOut: BigUInt, path: [EthereumAddress]) async throws -> [BigUInt]{ 254 | return try await (PancakeSwapCall?.getAmountsIn(contractAddress: contract, amountOut: amountOut, path: path))! 255 | } 256 | 257 | public func getAmountsOut(amountIn: BigUInt, path: [EthereumAddress]) async throws -> [BigUInt]{ 258 | return try await (PancakeSwapCall?.getAmountsOut(contractAddress: contract, amountIn: amountIn, path: path))! 259 | } 260 | 261 | 262 | public func quote(amountA: BigUInt,reserveA: BigUInt,reserveB: BigUInt, account: EthereumAccount) async throws -> String{ 263 | let gasPrice = try await client.eth_gasPrice() 264 | let transaction = try await (PancakeSwapCall?.quote(contractAddress:contract,amountA: amountA,reserveA: reserveA,reserveB: reserveB, from: account.address, gasPrice: gasPrice))! 265 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 266 | return txHash 267 | } 268 | 269 | 270 | public func removeLiquidity(tokenA: EthereumAddress,tokenB: EthereumAddress,liquidity: BigUInt,amountAMin: BigUInt,amountBMin: BigUInt,to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 271 | let gasPrice = try await client.eth_gasPrice() 272 | let transaction = try await (PancakeSwapCall?.removeLiquidity(contractAddress:contract,tokenA: tokenA,tokenB: tokenB,liquidity: liquidity,amountAMin: amountAMin,amountBMin: amountBMin,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 273 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 274 | return txHash 275 | } 276 | 277 | 278 | public func removeLiquidityETH(token: EthereumAddress,liquidity: BigUInt,amountTokenMin: BigUInt,amountETHMin: BigUInt,to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 279 | let gasPrice = try await client.eth_gasPrice() 280 | let transaction = try await (PancakeSwapCall?.removeLiquidityETH(contractAddress:contract,token: token,liquidity: liquidity,amountTokenMin: amountTokenMin,amountETHMin: amountETHMin,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 281 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 282 | return txHash 283 | } 284 | 285 | 286 | public func removeLiquidityETHSupportingFeeOnTransferTokens(token: EthereumAddress,liquidity: BigUInt,amountTokenMin: BigUInt,amountETHMin: BigUInt,to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 287 | let gasPrice = try await client.eth_gasPrice() 288 | let transaction = try await (PancakeSwapCall?.removeLiquidityETHSupportingFeeOnTransferTokens(contractAddress:contract,token: token,liquidity: liquidity,amountTokenMin: amountTokenMin,amountETHMin: amountETHMin,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 289 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 290 | return txHash 291 | } 292 | 293 | 294 | public func removeLiquidityETHWithPermit(token: EthereumAddress,liquidity: BigUInt,amountTokenMin: BigUInt,amountETHMin: BigUInt,to: EthereumAddress,deadline: BigUInt,approveMax: Bool,v: BigUInt,r: BigUInt,s: BigUInt, account: EthereumAccount) async throws -> String{ 295 | let gasPrice = try await client.eth_gasPrice() 296 | let transaction = try await (PancakeSwapCall?.removeLiquidityETHWithPermit(contractAddress:contract,token: token,liquidity: liquidity,amountTokenMin: amountTokenMin,amountETHMin: amountETHMin,to: to,deadline: deadline,approveMax: approveMax,v: v,r: r,s: s, from: account.address, gasPrice: gasPrice))! 297 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 298 | return txHash 299 | } 300 | 301 | 302 | public func removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(token: EthereumAddress,liquidity: BigUInt,amountTokenMin: BigUInt,amountETHMin: BigUInt,to: EthereumAddress,deadline: BigUInt,approveMax: Bool,v: BigUInt,r: BigUInt,s: BigUInt, account: EthereumAccount) async throws -> String{ 303 | let gasPrice = try await client.eth_gasPrice() 304 | let transaction = try await (PancakeSwapCall?.removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(contractAddress:contract,token: token,liquidity: liquidity,amountTokenMin: amountTokenMin,amountETHMin: amountETHMin,to: to,deadline: deadline,approveMax: approveMax,v: v,r: r,s: s, from: account.address, gasPrice: gasPrice))! 305 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 306 | return txHash 307 | } 308 | 309 | 310 | public func removeLiquidityWithPermit(tokenA: EthereumAddress,tokenB: EthereumAddress,liquidity: BigUInt,amountAMin: BigUInt,amountBMin: BigUInt,to: EthereumAddress,deadline: BigUInt,approveMax: Bool,v: BigUInt,r: BigUInt,s: BigUInt, account: EthereumAccount) async throws -> String{ 311 | let gasPrice = try await client.eth_gasPrice() 312 | let transaction = try await (PancakeSwapCall?.removeLiquidityWithPermit(contractAddress:contract,tokenA: tokenA,tokenB: tokenB,liquidity: liquidity,amountAMin: amountAMin,amountBMin: amountBMin,to: to,deadline: deadline,approveMax: approveMax,v: v,r: r,s: s, from: account.address, gasPrice: gasPrice))! 313 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 314 | return txHash 315 | } 316 | 317 | 318 | public func swapETHForExactTokens(amountOut: BigUInt,path: [EthereumAddress],to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 319 | let gasPrice = try await client.eth_gasPrice() 320 | let transaction = try await (PancakeSwapCall?.swapETHForExactTokens(contractAddress:contract,amountOut: amountOut,path: path,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 321 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 322 | return txHash 323 | } 324 | 325 | 326 | public func swapExactETHForTokens(amountOutMin: BigUInt,path: [EthereumAddress],to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 327 | let gasPrice = try await client.eth_gasPrice() 328 | let transaction = try await (PancakeSwapCall?.swapExactETHForTokens(contractAddress:contract,amountOutMin: amountOutMin,path: path,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 329 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 330 | return txHash 331 | } 332 | 333 | 334 | public func swapExactTokensForETH(amountIn: BigUInt,amountOutMin: BigUInt,path: [EthereumAddress],to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 335 | let gasPrice = try await client.eth_gasPrice() 336 | let transaction = try await (PancakeSwapCall?.swapExactTokensForETH(contractAddress:contract,amountIn: amountIn,amountOutMin: amountOutMin,path: path,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 337 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 338 | return txHash 339 | } 340 | 341 | 342 | public func swapExactTokensForTokens(amountIn: BigUInt,amountOutMin: BigUInt,path: [EthereumAddress],to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 343 | let gasPrice = try await client.eth_gasPrice() 344 | let transaction = try await (PancakeSwapCall?.swapExactTokensForTokens(contractAddress:contract,amountIn: amountIn,amountOutMin: amountOutMin,path: path,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 345 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 346 | return txHash 347 | } 348 | 349 | 350 | public func swapTokensForExactETH(amountOut: BigUInt,amountInMax: BigUInt,path: [EthereumAddress],to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 351 | let gasPrice = try await client.eth_gasPrice() 352 | let transaction = try await (PancakeSwapCall?.swapTokensForExactETH(contractAddress:contract,amountOut: amountOut,amountInMax: amountInMax,path: path,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 353 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 354 | return txHash 355 | } 356 | 357 | 358 | public func swapTokensForExactTokens(amountOut: BigUInt,amountInMax: BigUInt,path: [EthereumAddress],to: EthereumAddress,deadline: BigUInt, account: EthereumAccount) async throws -> String{ 359 | let gasPrice = try await client.eth_gasPrice() 360 | let transaction = try await (PancakeSwapCall?.swapTokensForExactTokens(contractAddress:contract,amountOut: amountOut,amountInMax: amountInMax,path: path,to: to,deadline: deadline, from: account.address, gasPrice: gasPrice))! 361 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 362 | return txHash 363 | } 364 | 365 | 366 | } 367 | extension PancakeSwap { 368 | public func WETH(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 369 | Task { 370 | do { 371 | let WETH = try await WETH(contractAddress: contractAddress ) 372 | completionHandler(.success(WETH)) 373 | } catch { 374 | completionHandler(.failure(error)) 375 | } 376 | } 377 | } 378 | public func factory(contractAddress: EthereumAddress, completionHandler: @escaping (Result) -> Void) { 379 | Task { 380 | do { 381 | let factory = try await factory(contractAddress: contractAddress ) 382 | completionHandler(.success(factory)) 383 | } catch { 384 | completionHandler(.failure(error)) 385 | } 386 | } 387 | } 388 | public func getAmountsIn(contractAddress: EthereumAddress, amountOut: BigUInt, path: [EthereumAddress], completionHandler: @escaping (Result<[BigUInt], Error>) -> Void) { 389 | Task { 390 | do { 391 | let getAmountsIn = try await getAmountsIn(contractAddress: contractAddress , amountOut: amountOut, path: path) 392 | completionHandler(.success(getAmountsIn)) 393 | } catch { 394 | completionHandler(.failure(error)) 395 | } 396 | } 397 | } 398 | public func getAmountsOut(contractAddress: EthereumAddress, amountIn: BigUInt, path: [EthereumAddress], completionHandler: @escaping (Result<[BigUInt], Error>) -> Void) { 399 | Task { 400 | do { 401 | let getAmountsOut = try await getAmountsOut(contractAddress: contractAddress , amountIn: amountIn, path: path) 402 | completionHandler(.success(getAmountsOut)) 403 | } catch { 404 | completionHandler(.failure(error)) 405 | } 406 | } 407 | } 408 | } 409 | -------------------------------------------------------------------------------- /PancakeSwap/PancakeSwapFunctions.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // swiftAbi 4 | // Don't change the files! this file is generated! 5 | // https://github.com/imanrep/ 6 | // 7 | 8 | import BigInt 9 | import Foundation 10 | import web3 11 | 12 | public enum PancakeSwapFunctions { 13 | public struct WETH: ABIFunction { 14 | public static let name = "WETH" 15 | public let gasPrice: BigUInt? 16 | public let gasLimit: BigUInt? 17 | public var contract: EthereumAddress 18 | public let from: EthereumAddress? 19 | 20 | 21 | 22 | public init( 23 | contract: EthereumAddress, 24 | from: EthereumAddress? = nil, 25 | gasPrice: BigUInt? = nil, 26 | gasLimit: BigUInt? = nil 27 | 28 | ) { 29 | self.contract = contract 30 | self.from = from 31 | self.gasPrice = gasPrice 32 | self.gasLimit = gasLimit 33 | 34 | } 35 | 36 | public func encode(to encoder: ABIFunctionEncoder) throws { 37 | 38 | } 39 | } 40 | public struct addLiquidity: ABIFunction { 41 | public static let name = "addLiquidity" 42 | public let gasPrice: BigUInt? 43 | public let gasLimit: BigUInt? 44 | public var contract: EthereumAddress 45 | public let from: EthereumAddress? 46 | 47 | public let tokenA: EthereumAddress 48 | public let tokenB: EthereumAddress 49 | public let amountADesired: BigUInt 50 | public let amountBDesired: BigUInt 51 | public let amountAMin: BigUInt 52 | public let amountBMin: BigUInt 53 | public let to: EthereumAddress 54 | public let deadline: BigUInt 55 | 56 | 57 | public init( 58 | contract: EthereumAddress, 59 | from: EthereumAddress? = nil, 60 | gasPrice: BigUInt? = nil, 61 | gasLimit: BigUInt? = nil, 62 | tokenA: EthereumAddress, 63 | tokenB: EthereumAddress, 64 | amountADesired: BigUInt, 65 | amountBDesired: BigUInt, 66 | amountAMin: BigUInt, 67 | amountBMin: BigUInt, 68 | to: EthereumAddress, 69 | deadline: BigUInt 70 | 71 | ) { 72 | self.contract = contract 73 | self.from = from 74 | self.gasPrice = gasPrice 75 | self.gasLimit = gasLimit 76 | self.tokenA = tokenA 77 | self.tokenB = tokenB 78 | self.amountADesired = amountADesired 79 | self.amountBDesired = amountBDesired 80 | self.amountAMin = amountAMin 81 | self.amountBMin = amountBMin 82 | self.to = to 83 | self.deadline = deadline 84 | 85 | } 86 | 87 | public func encode(to encoder: ABIFunctionEncoder) throws { 88 | try encoder.encode(tokenA) 89 | try encoder.encode(tokenB) 90 | try encoder.encode(amountADesired) 91 | try encoder.encode(amountBDesired) 92 | try encoder.encode(amountAMin) 93 | try encoder.encode(amountBMin) 94 | try encoder.encode(to) 95 | try encoder.encode(deadline) 96 | 97 | } 98 | } 99 | public struct addLiquidityETH: ABIFunction { 100 | public static let name = "addLiquidityETH" 101 | public let gasPrice: BigUInt? 102 | public let gasLimit: BigUInt? 103 | public var contract: EthereumAddress 104 | public let from: EthereumAddress? 105 | 106 | public let token: EthereumAddress 107 | public let amountTokenDesired: BigUInt 108 | public let amountTokenMin: BigUInt 109 | public let amountETHMin: BigUInt 110 | public let to: EthereumAddress 111 | public let deadline: BigUInt 112 | 113 | 114 | public init( 115 | contract: EthereumAddress, 116 | from: EthereumAddress? = nil, 117 | gasPrice: BigUInt? = nil, 118 | gasLimit: BigUInt? = nil, 119 | token: EthereumAddress, 120 | amountTokenDesired: BigUInt, 121 | amountTokenMin: BigUInt, 122 | amountETHMin: BigUInt, 123 | to: EthereumAddress, 124 | deadline: BigUInt 125 | 126 | ) { 127 | self.contract = contract 128 | self.from = from 129 | self.gasPrice = gasPrice 130 | self.gasLimit = gasLimit 131 | self.token = token 132 | self.amountTokenDesired = amountTokenDesired 133 | self.amountTokenMin = amountTokenMin 134 | self.amountETHMin = amountETHMin 135 | self.to = to 136 | self.deadline = deadline 137 | 138 | } 139 | 140 | public func encode(to encoder: ABIFunctionEncoder) throws { 141 | try encoder.encode(token) 142 | try encoder.encode(amountTokenDesired) 143 | try encoder.encode(amountTokenMin) 144 | try encoder.encode(amountETHMin) 145 | try encoder.encode(to) 146 | try encoder.encode(deadline) 147 | 148 | } 149 | } 150 | public struct factory: ABIFunction { 151 | public static let name = "factory" 152 | public let gasPrice: BigUInt? 153 | public let gasLimit: BigUInt? 154 | public var contract: EthereumAddress 155 | public let from: EthereumAddress? 156 | 157 | 158 | 159 | public init( 160 | contract: EthereumAddress, 161 | from: EthereumAddress? = nil, 162 | gasPrice: BigUInt? = nil, 163 | gasLimit: BigUInt? = nil 164 | 165 | ) { 166 | self.contract = contract 167 | self.from = from 168 | self.gasPrice = gasPrice 169 | self.gasLimit = gasLimit 170 | 171 | } 172 | 173 | public func encode(to encoder: ABIFunctionEncoder) throws { 174 | 175 | } 176 | } 177 | public struct getAmountIn: ABIFunction { 178 | public static let name = "getAmountIn" 179 | public let gasPrice: BigUInt? 180 | public let gasLimit: BigUInt? 181 | public var contract: EthereumAddress 182 | public let from: EthereumAddress? 183 | 184 | public let amountOut: BigUInt 185 | public let reserveIn: BigUInt 186 | public let reserveOut: BigUInt 187 | 188 | 189 | public init( 190 | contract: EthereumAddress, 191 | from: EthereumAddress? = nil, 192 | gasPrice: BigUInt? = nil, 193 | gasLimit: BigUInt? = nil, 194 | amountOut: BigUInt, 195 | reserveIn: BigUInt, 196 | reserveOut: BigUInt 197 | 198 | ) { 199 | self.contract = contract 200 | self.from = from 201 | self.gasPrice = gasPrice 202 | self.gasLimit = gasLimit 203 | self.amountOut = amountOut 204 | self.reserveIn = reserveIn 205 | self.reserveOut = reserveOut 206 | 207 | } 208 | 209 | public func encode(to encoder: ABIFunctionEncoder) throws { 210 | try encoder.encode(amountOut) 211 | try encoder.encode(reserveIn) 212 | try encoder.encode(reserveOut) 213 | 214 | } 215 | } 216 | public struct getAmountOut: ABIFunction { 217 | public static let name = "getAmountOut" 218 | public let gasPrice: BigUInt? 219 | public let gasLimit: BigUInt? 220 | public var contract: EthereumAddress 221 | public let from: EthereumAddress? 222 | 223 | public let amountIn: BigUInt 224 | public let reserveIn: BigUInt 225 | public let reserveOut: BigUInt 226 | 227 | 228 | public init( 229 | contract: EthereumAddress, 230 | from: EthereumAddress? = nil, 231 | gasPrice: BigUInt? = nil, 232 | gasLimit: BigUInt? = nil, 233 | amountIn: BigUInt, 234 | reserveIn: BigUInt, 235 | reserveOut: BigUInt 236 | 237 | ) { 238 | self.contract = contract 239 | self.from = from 240 | self.gasPrice = gasPrice 241 | self.gasLimit = gasLimit 242 | self.amountIn = amountIn 243 | self.reserveIn = reserveIn 244 | self.reserveOut = reserveOut 245 | 246 | } 247 | 248 | public func encode(to encoder: ABIFunctionEncoder) throws { 249 | try encoder.encode(amountIn) 250 | try encoder.encode(reserveIn) 251 | try encoder.encode(reserveOut) 252 | 253 | } 254 | } 255 | public struct getAmountsIn: ABIFunction { 256 | public static let name = "getAmountsIn" 257 | public let gasPrice: BigUInt? 258 | public let gasLimit: BigUInt? 259 | public var contract: EthereumAddress 260 | public let from: EthereumAddress? 261 | 262 | public let amountOut: BigUInt 263 | public let path: [EthereumAddress] 264 | 265 | 266 | public init( 267 | contract: EthereumAddress, 268 | from: EthereumAddress? = nil, 269 | gasPrice: BigUInt? = nil, 270 | gasLimit: BigUInt? = nil, 271 | amountOut: BigUInt, 272 | path: [EthereumAddress] 273 | 274 | ) { 275 | self.contract = contract 276 | self.from = from 277 | self.gasPrice = gasPrice 278 | self.gasLimit = gasLimit 279 | self.amountOut = amountOut 280 | self.path = path 281 | 282 | } 283 | 284 | public func encode(to encoder: ABIFunctionEncoder) throws { 285 | try encoder.encode(amountOut) 286 | try encoder.encode(path) 287 | 288 | } 289 | } 290 | public struct getAmountsOut: ABIFunction { 291 | public static let name = "getAmountsOut" 292 | public let gasPrice: BigUInt? 293 | public let gasLimit: BigUInt? 294 | public var contract: EthereumAddress 295 | public let from: EthereumAddress? 296 | 297 | public let amountIn: BigUInt 298 | public let path: [EthereumAddress] 299 | 300 | 301 | public init( 302 | contract: EthereumAddress, 303 | from: EthereumAddress? = nil, 304 | gasPrice: BigUInt? = nil, 305 | gasLimit: BigUInt? = nil, 306 | amountIn: BigUInt, 307 | path: [EthereumAddress] 308 | 309 | ) { 310 | self.contract = contract 311 | self.from = from 312 | self.gasPrice = gasPrice 313 | self.gasLimit = gasLimit 314 | self.amountIn = amountIn 315 | self.path = path 316 | 317 | } 318 | 319 | public func encode(to encoder: ABIFunctionEncoder) throws { 320 | try encoder.encode(amountIn) 321 | try encoder.encode(path) 322 | 323 | } 324 | } 325 | public struct quote: ABIFunction { 326 | public static let name = "quote" 327 | public let gasPrice: BigUInt? 328 | public let gasLimit: BigUInt? 329 | public var contract: EthereumAddress 330 | public let from: EthereumAddress? 331 | 332 | public let amountA: BigUInt 333 | public let reserveA: BigUInt 334 | public let reserveB: BigUInt 335 | 336 | 337 | public init( 338 | contract: EthereumAddress, 339 | from: EthereumAddress? = nil, 340 | gasPrice: BigUInt? = nil, 341 | gasLimit: BigUInt? = nil, 342 | amountA: BigUInt, 343 | reserveA: BigUInt, 344 | reserveB: BigUInt 345 | 346 | ) { 347 | self.contract = contract 348 | self.from = from 349 | self.gasPrice = gasPrice 350 | self.gasLimit = gasLimit 351 | self.amountA = amountA 352 | self.reserveA = reserveA 353 | self.reserveB = reserveB 354 | 355 | } 356 | 357 | public func encode(to encoder: ABIFunctionEncoder) throws { 358 | try encoder.encode(amountA) 359 | try encoder.encode(reserveA) 360 | try encoder.encode(reserveB) 361 | 362 | } 363 | } 364 | public struct removeLiquidity: ABIFunction { 365 | public static let name = "removeLiquidity" 366 | public let gasPrice: BigUInt? 367 | public let gasLimit: BigUInt? 368 | public var contract: EthereumAddress 369 | public let from: EthereumAddress? 370 | 371 | public let tokenA: EthereumAddress 372 | public let tokenB: EthereumAddress 373 | public let liquidity: BigUInt 374 | public let amountAMin: BigUInt 375 | public let amountBMin: BigUInt 376 | public let to: EthereumAddress 377 | public let deadline: BigUInt 378 | 379 | 380 | public init( 381 | contract: EthereumAddress, 382 | from: EthereumAddress? = nil, 383 | gasPrice: BigUInt? = nil, 384 | gasLimit: BigUInt? = nil, 385 | tokenA: EthereumAddress, 386 | tokenB: EthereumAddress, 387 | liquidity: BigUInt, 388 | amountAMin: BigUInt, 389 | amountBMin: BigUInt, 390 | to: EthereumAddress, 391 | deadline: BigUInt 392 | 393 | ) { 394 | self.contract = contract 395 | self.from = from 396 | self.gasPrice = gasPrice 397 | self.gasLimit = gasLimit 398 | self.tokenA = tokenA 399 | self.tokenB = tokenB 400 | self.liquidity = liquidity 401 | self.amountAMin = amountAMin 402 | self.amountBMin = amountBMin 403 | self.to = to 404 | self.deadline = deadline 405 | 406 | } 407 | 408 | public func encode(to encoder: ABIFunctionEncoder) throws { 409 | try encoder.encode(tokenA) 410 | try encoder.encode(tokenB) 411 | try encoder.encode(liquidity) 412 | try encoder.encode(amountAMin) 413 | try encoder.encode(amountBMin) 414 | try encoder.encode(to) 415 | try encoder.encode(deadline) 416 | 417 | } 418 | } 419 | public struct removeLiquidityETH: ABIFunction { 420 | public static let name = "removeLiquidityETH" 421 | public let gasPrice: BigUInt? 422 | public let gasLimit: BigUInt? 423 | public var contract: EthereumAddress 424 | public let from: EthereumAddress? 425 | 426 | public let token: EthereumAddress 427 | public let liquidity: BigUInt 428 | public let amountTokenMin: BigUInt 429 | public let amountETHMin: BigUInt 430 | public let to: EthereumAddress 431 | public let deadline: BigUInt 432 | 433 | 434 | public init( 435 | contract: EthereumAddress, 436 | from: EthereumAddress? = nil, 437 | gasPrice: BigUInt? = nil, 438 | gasLimit: BigUInt? = nil, 439 | token: EthereumAddress, 440 | liquidity: BigUInt, 441 | amountTokenMin: BigUInt, 442 | amountETHMin: BigUInt, 443 | to: EthereumAddress, 444 | deadline: BigUInt 445 | 446 | ) { 447 | self.contract = contract 448 | self.from = from 449 | self.gasPrice = gasPrice 450 | self.gasLimit = gasLimit 451 | self.token = token 452 | self.liquidity = liquidity 453 | self.amountTokenMin = amountTokenMin 454 | self.amountETHMin = amountETHMin 455 | self.to = to 456 | self.deadline = deadline 457 | 458 | } 459 | 460 | public func encode(to encoder: ABIFunctionEncoder) throws { 461 | try encoder.encode(token) 462 | try encoder.encode(liquidity) 463 | try encoder.encode(amountTokenMin) 464 | try encoder.encode(amountETHMin) 465 | try encoder.encode(to) 466 | try encoder.encode(deadline) 467 | 468 | } 469 | } 470 | public struct removeLiquidityETHSupportingFeeOnTransferTokens: ABIFunction { 471 | public static let name = "removeLiquidityETHSupportingFeeOnTransferTokens" 472 | public let gasPrice: BigUInt? 473 | public let gasLimit: BigUInt? 474 | public var contract: EthereumAddress 475 | public let from: EthereumAddress? 476 | 477 | public let token: EthereumAddress 478 | public let liquidity: BigUInt 479 | public let amountTokenMin: BigUInt 480 | public let amountETHMin: BigUInt 481 | public let to: EthereumAddress 482 | public let deadline: BigUInt 483 | 484 | 485 | public init( 486 | contract: EthereumAddress, 487 | from: EthereumAddress? = nil, 488 | gasPrice: BigUInt? = nil, 489 | gasLimit: BigUInt? = nil, 490 | token: EthereumAddress, 491 | liquidity: BigUInt, 492 | amountTokenMin: BigUInt, 493 | amountETHMin: BigUInt, 494 | to: EthereumAddress, 495 | deadline: BigUInt 496 | 497 | ) { 498 | self.contract = contract 499 | self.from = from 500 | self.gasPrice = gasPrice 501 | self.gasLimit = gasLimit 502 | self.token = token 503 | self.liquidity = liquidity 504 | self.amountTokenMin = amountTokenMin 505 | self.amountETHMin = amountETHMin 506 | self.to = to 507 | self.deadline = deadline 508 | 509 | } 510 | 511 | public func encode(to encoder: ABIFunctionEncoder) throws { 512 | try encoder.encode(token) 513 | try encoder.encode(liquidity) 514 | try encoder.encode(amountTokenMin) 515 | try encoder.encode(amountETHMin) 516 | try encoder.encode(to) 517 | try encoder.encode(deadline) 518 | 519 | } 520 | } 521 | public struct removeLiquidityETHWithPermit: ABIFunction { 522 | public static let name = "removeLiquidityETHWithPermit" 523 | public let gasPrice: BigUInt? 524 | public let gasLimit: BigUInt? 525 | public var contract: EthereumAddress 526 | public let from: EthereumAddress? 527 | 528 | public let token: EthereumAddress 529 | public let liquidity: BigUInt 530 | public let amountTokenMin: BigUInt 531 | public let amountETHMin: BigUInt 532 | public let to: EthereumAddress 533 | public let deadline: BigUInt 534 | public let approveMax: Bool 535 | public let v: BigUInt 536 | public let r: BigUInt 537 | public let s: BigUInt 538 | 539 | 540 | public init( 541 | contract: EthereumAddress, 542 | from: EthereumAddress? = nil, 543 | gasPrice: BigUInt? = nil, 544 | gasLimit: BigUInt? = nil, 545 | token: EthereumAddress, 546 | liquidity: BigUInt, 547 | amountTokenMin: BigUInt, 548 | amountETHMin: BigUInt, 549 | to: EthereumAddress, 550 | deadline: BigUInt, 551 | approveMax: Bool, 552 | v: BigUInt, 553 | r: BigUInt, 554 | s: BigUInt 555 | 556 | ) { 557 | self.contract = contract 558 | self.from = from 559 | self.gasPrice = gasPrice 560 | self.gasLimit = gasLimit 561 | self.token = token 562 | self.liquidity = liquidity 563 | self.amountTokenMin = amountTokenMin 564 | self.amountETHMin = amountETHMin 565 | self.to = to 566 | self.deadline = deadline 567 | self.approveMax = approveMax 568 | self.v = v 569 | self.r = r 570 | self.s = s 571 | 572 | } 573 | 574 | public func encode(to encoder: ABIFunctionEncoder) throws { 575 | try encoder.encode(token) 576 | try encoder.encode(liquidity) 577 | try encoder.encode(amountTokenMin) 578 | try encoder.encode(amountETHMin) 579 | try encoder.encode(to) 580 | try encoder.encode(deadline) 581 | try encoder.encode(approveMax) 582 | try encoder.encode(v) 583 | try encoder.encode(r) 584 | try encoder.encode(s) 585 | 586 | } 587 | } 588 | public struct removeLiquidityETHWithPermitSupportingFeeOnTransferTokens: ABIFunction { 589 | public static let name = "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens" 590 | public let gasPrice: BigUInt? 591 | public let gasLimit: BigUInt? 592 | public var contract: EthereumAddress 593 | public let from: EthereumAddress? 594 | 595 | public let token: EthereumAddress 596 | public let liquidity: BigUInt 597 | public let amountTokenMin: BigUInt 598 | public let amountETHMin: BigUInt 599 | public let to: EthereumAddress 600 | public let deadline: BigUInt 601 | public let approveMax: Bool 602 | public let v: BigUInt 603 | public let r: BigUInt 604 | public let s: BigUInt 605 | 606 | 607 | public init( 608 | contract: EthereumAddress, 609 | from: EthereumAddress? = nil, 610 | gasPrice: BigUInt? = nil, 611 | gasLimit: BigUInt? = nil, 612 | token: EthereumAddress, 613 | liquidity: BigUInt, 614 | amountTokenMin: BigUInt, 615 | amountETHMin: BigUInt, 616 | to: EthereumAddress, 617 | deadline: BigUInt, 618 | approveMax: Bool, 619 | v: BigUInt, 620 | r: BigUInt, 621 | s: BigUInt 622 | 623 | ) { 624 | self.contract = contract 625 | self.from = from 626 | self.gasPrice = gasPrice 627 | self.gasLimit = gasLimit 628 | self.token = token 629 | self.liquidity = liquidity 630 | self.amountTokenMin = amountTokenMin 631 | self.amountETHMin = amountETHMin 632 | self.to = to 633 | self.deadline = deadline 634 | self.approveMax = approveMax 635 | self.v = v 636 | self.r = r 637 | self.s = s 638 | 639 | } 640 | 641 | public func encode(to encoder: ABIFunctionEncoder) throws { 642 | try encoder.encode(token) 643 | try encoder.encode(liquidity) 644 | try encoder.encode(amountTokenMin) 645 | try encoder.encode(amountETHMin) 646 | try encoder.encode(to) 647 | try encoder.encode(deadline) 648 | try encoder.encode(approveMax) 649 | try encoder.encode(v) 650 | try encoder.encode(r) 651 | try encoder.encode(s) 652 | 653 | } 654 | } 655 | public struct removeLiquidityWithPermit: ABIFunction { 656 | public static let name = "removeLiquidityWithPermit" 657 | public let gasPrice: BigUInt? 658 | public let gasLimit: BigUInt? 659 | public var contract: EthereumAddress 660 | public let from: EthereumAddress? 661 | 662 | public let tokenA: EthereumAddress 663 | public let tokenB: EthereumAddress 664 | public let liquidity: BigUInt 665 | public let amountAMin: BigUInt 666 | public let amountBMin: BigUInt 667 | public let to: EthereumAddress 668 | public let deadline: BigUInt 669 | public let approveMax: Bool 670 | public let v: BigUInt 671 | public let r: BigUInt 672 | public let s: BigUInt 673 | 674 | 675 | public init( 676 | contract: EthereumAddress, 677 | from: EthereumAddress? = nil, 678 | gasPrice: BigUInt? = nil, 679 | gasLimit: BigUInt? = nil, 680 | tokenA: EthereumAddress, 681 | tokenB: EthereumAddress, 682 | liquidity: BigUInt, 683 | amountAMin: BigUInt, 684 | amountBMin: BigUInt, 685 | to: EthereumAddress, 686 | deadline: BigUInt, 687 | approveMax: Bool, 688 | v: BigUInt, 689 | r: BigUInt, 690 | s: BigUInt 691 | 692 | ) { 693 | self.contract = contract 694 | self.from = from 695 | self.gasPrice = gasPrice 696 | self.gasLimit = gasLimit 697 | self.tokenA = tokenA 698 | self.tokenB = tokenB 699 | self.liquidity = liquidity 700 | self.amountAMin = amountAMin 701 | self.amountBMin = amountBMin 702 | self.to = to 703 | self.deadline = deadline 704 | self.approveMax = approveMax 705 | self.v = v 706 | self.r = r 707 | self.s = s 708 | 709 | } 710 | 711 | public func encode(to encoder: ABIFunctionEncoder) throws { 712 | try encoder.encode(tokenA) 713 | try encoder.encode(tokenB) 714 | try encoder.encode(liquidity) 715 | try encoder.encode(amountAMin) 716 | try encoder.encode(amountBMin) 717 | try encoder.encode(to) 718 | try encoder.encode(deadline) 719 | try encoder.encode(approveMax) 720 | try encoder.encode(v) 721 | try encoder.encode(r) 722 | try encoder.encode(s) 723 | 724 | } 725 | } 726 | public struct swapETHForExactTokens: ABIFunction { 727 | public static let name = "swapETHForExactTokens" 728 | public let gasPrice: BigUInt? 729 | public let gasLimit: BigUInt? 730 | public var contract: EthereumAddress 731 | public let from: EthereumAddress? 732 | 733 | public let amountOut: BigUInt 734 | public let path: [EthereumAddress] 735 | public let to: EthereumAddress 736 | public let deadline: BigUInt 737 | 738 | 739 | public init( 740 | contract: EthereumAddress, 741 | from: EthereumAddress? = nil, 742 | gasPrice: BigUInt? = nil, 743 | gasLimit: BigUInt? = nil, 744 | amountOut: BigUInt, 745 | path: [EthereumAddress], 746 | to: EthereumAddress, 747 | deadline: BigUInt 748 | 749 | ) { 750 | self.contract = contract 751 | self.from = from 752 | self.gasPrice = gasPrice 753 | self.gasLimit = gasLimit 754 | self.amountOut = amountOut 755 | self.path = path 756 | self.to = to 757 | self.deadline = deadline 758 | 759 | } 760 | 761 | public func encode(to encoder: ABIFunctionEncoder) throws { 762 | try encoder.encode(amountOut) 763 | try encoder.encode(path) 764 | try encoder.encode(to) 765 | try encoder.encode(deadline) 766 | 767 | } 768 | } 769 | public struct swapExactETHForTokens: ABIFunction { 770 | public static let name = "swapExactETHForTokens" 771 | public let gasPrice: BigUInt? 772 | public let gasLimit: BigUInt? 773 | public var contract: EthereumAddress 774 | public let from: EthereumAddress? 775 | 776 | public let amountOutMin: BigUInt 777 | public let path: [EthereumAddress] 778 | public let to: EthereumAddress 779 | public let deadline: BigUInt 780 | 781 | 782 | public init( 783 | contract: EthereumAddress, 784 | from: EthereumAddress? = nil, 785 | gasPrice: BigUInt? = nil, 786 | gasLimit: BigUInt? = nil, 787 | amountOutMin: BigUInt, 788 | path: [EthereumAddress], 789 | to: EthereumAddress, 790 | deadline: BigUInt 791 | 792 | ) { 793 | self.contract = contract 794 | self.from = from 795 | self.gasPrice = gasPrice 796 | self.gasLimit = gasLimit 797 | self.amountOutMin = amountOutMin 798 | self.path = path 799 | self.to = to 800 | self.deadline = deadline 801 | 802 | } 803 | 804 | public func encode(to encoder: ABIFunctionEncoder) throws { 805 | try encoder.encode(amountOutMin) 806 | try encoder.encode(path) 807 | try encoder.encode(to) 808 | try encoder.encode(deadline) 809 | 810 | } 811 | } 812 | public struct swapExactTokensForETH: ABIFunction { 813 | public static let name = "swapExactTokensForETH" 814 | public let gasPrice: BigUInt? 815 | public let gasLimit: BigUInt? 816 | public var contract: EthereumAddress 817 | public let from: EthereumAddress? 818 | 819 | public let amountIn: BigUInt 820 | public let amountOutMin: BigUInt 821 | public let path: [EthereumAddress] 822 | public let to: EthereumAddress 823 | public let deadline: BigUInt 824 | 825 | 826 | public init( 827 | contract: EthereumAddress, 828 | from: EthereumAddress? = nil, 829 | gasPrice: BigUInt? = nil, 830 | gasLimit: BigUInt? = nil, 831 | amountIn: BigUInt, 832 | amountOutMin: BigUInt, 833 | path: [EthereumAddress], 834 | to: EthereumAddress, 835 | deadline: BigUInt 836 | 837 | ) { 838 | self.contract = contract 839 | self.from = from 840 | self.gasPrice = gasPrice 841 | self.gasLimit = gasLimit 842 | self.amountIn = amountIn 843 | self.amountOutMin = amountOutMin 844 | self.path = path 845 | self.to = to 846 | self.deadline = deadline 847 | 848 | } 849 | 850 | public func encode(to encoder: ABIFunctionEncoder) throws { 851 | try encoder.encode(amountIn) 852 | try encoder.encode(amountOutMin) 853 | try encoder.encode(path) 854 | try encoder.encode(to) 855 | try encoder.encode(deadline) 856 | 857 | } 858 | } 859 | public struct swapExactTokensForTokens: ABIFunction { 860 | public static let name = "swapExactTokensForTokens" 861 | public let gasPrice: BigUInt? 862 | public let gasLimit: BigUInt? 863 | public var contract: EthereumAddress 864 | public let from: EthereumAddress? 865 | 866 | public let amountIn: BigUInt 867 | public let amountOutMin: BigUInt 868 | public let path: [EthereumAddress] 869 | public let to: EthereumAddress 870 | public let deadline: BigUInt 871 | 872 | 873 | public init( 874 | contract: EthereumAddress, 875 | from: EthereumAddress? = nil, 876 | gasPrice: BigUInt? = nil, 877 | gasLimit: BigUInt? = nil, 878 | amountIn: BigUInt, 879 | amountOutMin: BigUInt, 880 | path: [EthereumAddress], 881 | to: EthereumAddress, 882 | deadline: BigUInt 883 | 884 | ) { 885 | self.contract = contract 886 | self.from = from 887 | self.gasPrice = gasPrice 888 | self.gasLimit = gasLimit 889 | self.amountIn = amountIn 890 | self.amountOutMin = amountOutMin 891 | self.path = path 892 | self.to = to 893 | self.deadline = deadline 894 | 895 | } 896 | 897 | public func encode(to encoder: ABIFunctionEncoder) throws { 898 | try encoder.encode(amountIn) 899 | try encoder.encode(amountOutMin) 900 | try encoder.encode(path) 901 | try encoder.encode(to) 902 | try encoder.encode(deadline) 903 | 904 | } 905 | } 906 | public struct swapTokensForExactETH: ABIFunction { 907 | public static let name = "swapTokensForExactETH" 908 | public let gasPrice: BigUInt? 909 | public let gasLimit: BigUInt? 910 | public var contract: EthereumAddress 911 | public let from: EthereumAddress? 912 | 913 | public let amountOut: BigUInt 914 | public let amountInMax: BigUInt 915 | public let path: [EthereumAddress] 916 | public let to: EthereumAddress 917 | public let deadline: BigUInt 918 | 919 | 920 | public init( 921 | contract: EthereumAddress, 922 | from: EthereumAddress? = nil, 923 | gasPrice: BigUInt? = nil, 924 | gasLimit: BigUInt? = nil, 925 | amountOut: BigUInt, 926 | amountInMax: BigUInt, 927 | path: [EthereumAddress], 928 | to: EthereumAddress, 929 | deadline: BigUInt 930 | 931 | ) { 932 | self.contract = contract 933 | self.from = from 934 | self.gasPrice = gasPrice 935 | self.gasLimit = gasLimit 936 | self.amountOut = amountOut 937 | self.amountInMax = amountInMax 938 | self.path = path 939 | self.to = to 940 | self.deadline = deadline 941 | 942 | } 943 | 944 | public func encode(to encoder: ABIFunctionEncoder) throws { 945 | try encoder.encode(amountOut) 946 | try encoder.encode(amountInMax) 947 | try encoder.encode(path) 948 | try encoder.encode(to) 949 | try encoder.encode(deadline) 950 | 951 | } 952 | } 953 | public struct swapTokensForExactTokens: ABIFunction { 954 | public static let name = "swapTokensForExactTokens" 955 | public let gasPrice: BigUInt? 956 | public let gasLimit: BigUInt? 957 | public var contract: EthereumAddress 958 | public let from: EthereumAddress? 959 | 960 | public let amountOut: BigUInt 961 | public let amountInMax: BigUInt 962 | public let path: [EthereumAddress] 963 | public let to: EthereumAddress 964 | public let deadline: BigUInt 965 | 966 | 967 | public init( 968 | contract: EthereumAddress, 969 | from: EthereumAddress? = nil, 970 | gasPrice: BigUInt? = nil, 971 | gasLimit: BigUInt? = nil, 972 | amountOut: BigUInt, 973 | amountInMax: BigUInt, 974 | path: [EthereumAddress], 975 | to: EthereumAddress, 976 | deadline: BigUInt 977 | 978 | ) { 979 | self.contract = contract 980 | self.from = from 981 | self.gasPrice = gasPrice 982 | self.gasLimit = gasLimit 983 | self.amountOut = amountOut 984 | self.amountInMax = amountInMax 985 | self.path = path 986 | self.to = to 987 | self.deadline = deadline 988 | 989 | } 990 | 991 | public func encode(to encoder: ABIFunctionEncoder) throws { 992 | try encoder.encode(amountOut) 993 | try encoder.encode(amountInMax) 994 | try encoder.encode(path) 995 | try encoder.encode(to) 996 | try encoder.encode(deadline) 997 | 998 | } 999 | } 1000 | 1001 | } 1002 | -------------------------------------------------------------------------------- /PancakeSwap/PancakeSwapResponses.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // swiftAbi 4 | // Don't change the files! this file is generated! 5 | // https://github.com/imanrep/ 6 | // 7 | 8 | import BigInt 9 | import Foundation 10 | import web3 11 | 12 | public enum PancakeSwapResponses { 13 | public struct WETHResponse: ABIResponse, MulticallDecodableResponse { 14 | public static var types: [ABIType.Type] = [EthereumAddress.self] 15 | public let value: EthereumAddress 16 | 17 | public init?(values: [ABIDecoder.DecodedValue]) throws { 18 | 19 | self.value = try values[0].decoded() 20 | 21 | } 22 | } 23 | public struct factoryResponse: ABIResponse, MulticallDecodableResponse { 24 | public static var types: [ABIType.Type] = [EthereumAddress.self] 25 | public let value: EthereumAddress 26 | 27 | public init?(values: [ABIDecoder.DecodedValue]) throws { 28 | 29 | self.value = try values[0].decoded() 30 | 31 | } 32 | } 33 | public struct getAmountsInResponse: ABIResponse, MulticallDecodableResponse { 34 | public static var types: [ABIType.Type] = [ABIArray.self] 35 | public let value: [BigUInt] 36 | 37 | public init?(values: [ABIDecoder.DecodedValue]) throws { 38 | 39 | self.value = try values[0].decodedArray() 40 | 41 | } 42 | } 43 | public struct getAmountsOutResponse: ABIResponse, MulticallDecodableResponse { 44 | public static var types: [ABIType.Type] = [ABIArray.self] 45 | public let value: [BigUInt] 46 | 47 | public init?(values: [ABIDecoder.DecodedValue]) throws { 48 | 49 | self.value = try values[0].decodedArray() 50 | 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swiftabigen 2 | Convert EVM Contract ABI from json to swift file 3 | 4 | 5 | # How to install 6 | 1. Install NodeJS on your system 7 | 2. Install NPM package ```npm i swiftabigen --location=global``` 8 | 3. After installation you can use command ```npx swiftabigen filename``` filename is name of json ABI file without extension 9 | 4. File will be generated under folder (see picture below) 10 | 11 | ![image](https://user-images.githubusercontent.com/86184667/214624360-05bd5dda-8269-47ce-ba16-c2737dc395bc.png) 12 | 13 | 5. Open your XCode Project and create Group with name **CustomAbi** 14 | 6. Click Add files to "project" and import the folder 15 | 16 | ![Screenshot 2023-01-25 at 17 27 07](https://user-images.githubusercontent.com/86184667/214625677-cf9f41d2-3f0c-4432-96ae-1213e2be1faf.png) 17 | 18 | Make sure you choose create groups! 19 | 20 | ![Screenshot 2023-01-25 at 17 28 09](https://user-images.githubusercontent.com/86184667/214625851-6b6bc628-e5fb-42f2-ae9c-1a5c7cda3807.png) 21 | 22 | Tara! your ABI was successfully imported. 23 | 24 | ![Screenshot 2023-01-25 at 17 29 04](https://user-images.githubusercontent.com/86184667/214626423-7b7a368d-d1a3-41e6-bfef-35161c72e59d.png) 25 | 26 | 27 | # How to use 28 | You no need to declare contract to every functions. you only need declare for the Contract and use the functions! 29 | ## IERC20 example 30 | ### Transfer 31 | ```swift 32 | func test_contract() async { 33 | do { 34 | let x = IERC20Contract(contract: "0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684", client: client) 35 | let name = try await x.name() 36 | print(name) 37 | }catch { 38 | 39 | } 40 | } 41 | ``` 42 | 43 | ![Screenshot 2023-01-25 at 17 33 42](https://user-images.githubusercontent.com/86184667/214627435-7b348f83-3e39-43be-a54c-a0c8f5bad2f5.png) 44 | 45 | ### Token Transfer (nonPayable) 46 | ```swift 47 | func test_contract() async { 48 | do { 49 | let x = IERC20Contract(contract: "0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684", client: client) 50 | let txHash = try await x.transfer(recepient: EthereumAddress("0x7ef95a0FEE0Dd31b22626fA2e10Ee6A223F8a684"), amount BigUInt(100000000000), account : account) 51 | print(txHash) 52 | }catch { 53 | 54 | } 55 | } 56 | ``` 57 | 58 | ![Screenshot 2023-01-25 at 17 39 22](https://user-images.githubusercontent.com/86184667/214628435-4f785121-8602-44f8-9a65-a7a0cdc6972b.png) 59 | 60 | # Dependencies 61 | web3.swift 62 | 63 | ReadMe 64 | 65 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swiftabi", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "swiftabi", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "bin": { 12 | "swiftabi": "start.js" 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swiftabigen", 3 | "version": "1.0.0", 4 | "description": "Convert EVM Contract ABI from json to swift file", 5 | "author": "imanrep", 6 | "license": "ISC", 7 | "bin": { 8 | "swiftabi": "./start.js" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /start.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const fs = require('fs') 3 | 4 | 5 | const defaultProtocolFunction = (name, returnType, input, state) => { 6 | return `func ${name}(contractAddress: EthereumAddress ${input.map((data) => (`, ${data.name}: ${data.type}`)).join('')} ${state ? '' : ",from: EthereumAddress, gasPrice: BigUInt"}) async throws -> ${state ? returnType.length <= 1 ? returnType[0].type : `(${returnType.map((data, i) => (`${data.type}${returnType.length - 1 == i ? '' : ', '}`)).join('')})` : 'EthereumTransaction'}` 7 | } 8 | const defaultPublicFunction = (file, name, returnType, input) => { 9 | return `public func ${name}(contractAddress: EthereumAddress ${input.map((data, i) => (`, ${data.name}: ${data.type}`)).join('')}) async throws -> ${returnType.length <= 1 ? returnType[0].type : `(${returnType.map((data, i) => (`${data.type}${returnType.length - 1 == i ? '' : ', '}`)).join('')})`} { 10 | let function = ${file}Functions.${name}(contract: contractAddress ${input.map((data, i) => (`, ${data.name}: ${data.name}`)).join('')}) 11 | let data = try await function.call(withClient: client, responseType: ${file}Responses.${name}Response.self) 12 | return ${returnType.length <= 1 ? 'data.value' : `(${returnType.map((data, i) => (`data.value${i != 0 ? i : ""}${returnType.length - 1 == i ? '' : ', '}`)).join('')})`} 13 | }` 14 | } 15 | 16 | const defaultPublicPayableFunction = (file, name, input) => { 17 | return `public func ${name}(contractAddress: EthereumAddress ${input.map((data, i) => (`, ${data.name}: ${data.type}`)).join('')}, from: EthereumAddress, gasPrice: BigUInt) async throws -> EthereumTransaction { 18 | let tryCall = ${file}Functions.${name}(contract: contractAddress, from: from, gasPrice: gasPrice${input.map((data, i) => (`, ${data.name}: ${data.name}`)).join('')}) 19 | let subdata = try tryCall.transaction() 20 | let gas = try await client.eth_estimateGas(subdata) 21 | let function = ${file}Functions.${name}(contract: contractAddress, from: from, gasPrice: gasPrice,gasLimit: gas${input.map((data, i) => (`, ${data.name}: ${data.name}`)).join('')}) 22 | let data = try function.transaction() 23 | return data 24 | }` 25 | } 26 | const defaultExtensionFunction = (name, returnType, input) => { 27 | return `public func ${name}(contractAddress: EthereumAddress, ${input.map((data, i) => (`${data.name}: ${data.type}, `)).join('')} completionHandler: @escaping (Result<${returnType.length <= 1 ? returnType[0].type : `(${returnType.map((data, i) => (`${data.type}${returnType.length - 1 == i ? '' : ', '}`)).join('')})`}, Error>) -> Void) { 28 | Task { 29 | do { 30 | let ${name} = try await ${name}(contractAddress: contractAddress ${input.map((data, i) => (`, ${data.name}: ${data.name}`)).join('')}) 31 | completionHandler(.success(${name})) 32 | } catch { 33 | completionHandler(.failure(error)) 34 | } 35 | } 36 | }` 37 | } 38 | 39 | const defaultResponse = (name, ret) => { 40 | return `public struct ${name}Response: ABIResponse, MulticallDecodableResponse { 41 | public static var types: [ABIType.Type] = [${ret.map((data, i) => (`${handleTypeResponse(data.type)}.self${ret.length - 1 == i ? '' : ', '}`)).join('')}] 42 | ${ret.map((data, i) => (`public let value${i == 0 ? "" : i}: ${data.type}\n `)).join('')} 43 | public init?(values: [ABIDecoder.DecodedValue]) throws { 44 | 45 | ${ret.map((data, i) => (`self.value${i == 0 ? "" : i} = try values[${i}].${handleTypeResponse(data.type).includes(">") ? "decodedArray" :"decoded"}()\n `)).join('')} 46 | } 47 | }` 48 | } 49 | 50 | const handleInputFunctionResponse = (name, input) => { 51 | return `public struct ${name}: ABIFunction { 52 | public static let name = "${name}" 53 | public let gasPrice: BigUInt? 54 | public let gasLimit: BigUInt? 55 | public var contract: EthereumAddress 56 | public let from: EthereumAddress? 57 | 58 | ${input.map(data => ( 59 | `public let ${data.name}: ${data.type}\n ` 60 | )).join('')} 61 | 62 | public init( 63 | contract: EthereumAddress, 64 | from: EthereumAddress? = nil, 65 | gasPrice: BigUInt? = nil, 66 | gasLimit: BigUInt? = nil${input.length ? "," : ""} 67 | ${input.map((data, i) => ( 68 | `${data.name}: ${data.type}${input.length - 1 == i ? '' : ','}\n ` 69 | )).join('')} 70 | ) { 71 | self.contract = contract 72 | self.from = from 73 | self.gasPrice = gasPrice 74 | self.gasLimit = gasLimit 75 | ${input.map((data, i) => ( 76 | `self.${data.name} = ${data.name}\n ` 77 | )).join('')} 78 | } 79 | 80 | public func encode(to encoder: ABIFunctionEncoder) throws { 81 | ${input.map((data, i) => ( 82 | `try encoder.encode(${data.name})\n ` 83 | )).join('')} 84 | } 85 | }` 86 | } 87 | const handleType = (type) => { 88 | switch (type) { 89 | case "address": 90 | return "EthereumAddress" 91 | case "string": 92 | return "String" 93 | case "address[]": 94 | return "[EthereumAddress]" 95 | case "uint": 96 | return "BigUInt" 97 | case "uint8": 98 | return "BigUInt" 99 | case "uint256": 100 | return "BigUInt" 101 | case "uint256[]": 102 | return "[BigUInt]" 103 | case "int8": 104 | return "BigUInt" 105 | case "int256": 106 | return "BigUInt" 107 | case "bool": 108 | return "Bool" 109 | case "bytes32": 110 | return "BigUInt" 111 | default: 112 | throw `type data of ${type} is undefinied. please check again your abi` 113 | } 114 | } 115 | 116 | const handleTypeResponse = (type) => { 117 | switch (type) { 118 | case "EthereumAddress": 119 | return "EthereumAddress" 120 | case "String": 121 | return "String" 122 | case "[EthereumAddress]": 123 | return "ABIArray" 124 | case "[BigUInt]": 125 | return "ABIArray" 126 | case "BigUInt": 127 | return "BigUInt" 128 | case "Bool": 129 | return "Bool" 130 | case "bytes32": 131 | return "BigUInt" 132 | default: 133 | throw `type data of ${type} is undefinied. please check again your abi` 134 | } 135 | } 136 | 137 | function contractCall(name, funcName, func, input, state) { 138 | if(state) { 139 | return `public func ${funcName}(${input.map((data, i) => (`${data.name}: ${data.type}${input.length - 1 == i ? '' : ', '}`)).join('')}) async throws -> ${func.length <= 1 ? func[0].type : `(${func.map((data, i) => (`${data.type}${func.length - 1 == i ? '' : ', '}`)).join('')})`}{ 140 | return try await (${name}Call?.${funcName}(contractAddress: contract${input.map((data, i) => (`, ${data.name}: ${data.name}`)).join('')}))! 141 | }\n ` 142 | }else { 143 | return ` 144 | public func ${funcName}(${input.map((data, i) => (`${data.name}: ${data.type},`)).join('')} account: EthereumAccount) async throws -> String{ 145 | let gasPrice = try await client.eth_gasPrice() 146 | let transaction = try await (${name}Call?.${funcName}(contractAddress:contract${input.map((data, i) => (`,${data.name}: ${data.name}`)).join('')}, from: account.address, gasPrice: gasPrice))! 147 | let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account) 148 | return txHash 149 | }\n ` 150 | } 151 | 152 | } 153 | function main(name, func, publicFunc, exFunc, f) { 154 | return ` 155 | // 156 | // swiftAbi 157 | // Don't change the files! this file is generated! 158 | // https://github.com/imanrep/ 159 | // 160 | 161 | import BigInt 162 | import Foundation 163 | import web3 164 | 165 | public protocol ${name}Protocol { 166 | init(client: EthereumClientProtocol) 167 | 168 | ${func.join("\n ")} 169 | } 170 | 171 | open class ${name}: ${name}Protocol { 172 | let client: EthereumClientProtocol 173 | 174 | required public init(client: EthereumClientProtocol) { 175 | self.client = client 176 | } 177 | 178 | ${publicFunc.join("\n ")} 179 | 180 | } 181 | open class ${name}Contract { 182 | var ${name}Call: ${name}? 183 | var client: EthereumClientProtocol 184 | var contract: web3.EthereumAddress 185 | 186 | init(contract: String, client: EthereumClientProtocol) { 187 | self.contract = EthereumAddress(contract) 188 | self.client = client 189 | self.${name}Call = ${name}(client: client) 190 | } 191 | ${f.join("\n ")} 192 | 193 | } 194 | extension ${name} { 195 | ${exFunc.join("\n ")} 196 | } 197 | ` 198 | } 199 | 200 | function response(name, func) { 201 | return ` 202 | // 203 | // swiftAbi 204 | // Don't change the files! this file is generated! 205 | // https://github.com/imanrep/ 206 | // 207 | 208 | import BigInt 209 | import Foundation 210 | import web3 211 | 212 | public enum ${name}Responses { 213 | ${func.join("\n ")} 214 | 215 | } 216 | ` 217 | } 218 | 219 | function ABIFunction(name, func) { 220 | return ` 221 | // 222 | // swiftAbi 223 | // Don't change the files! this file is generated! 224 | // https://github.com/imanrep/ 225 | // 226 | 227 | import BigInt 228 | import Foundation 229 | import web3 230 | 231 | public enum ${name}Functions { 232 | ${func.join("\n ")} 233 | 234 | } 235 | ` 236 | } 237 | 238 | function handleInput(list) { 239 | var res = [] 240 | for(let i = 0; i< list.length;i++) { 241 | res.push({name:list[i].name, type:handleType(list[i].type)}) 242 | } 243 | return res 244 | } 245 | function handleOutput(list) { 246 | var res = [] 247 | for(let i = 0; i< list.length;i++) { 248 | res.push({name:list[i].name, type:handleType(list[i].type)}) 249 | } 250 | return res 251 | } 252 | function start() { 253 | var name = process.argv.slice(2); 254 | try { 255 | fs.readFileSync(`${name[0]}.json`); 256 | }catch { 257 | throw `${name[0]}.json is not found` 258 | } 259 | var raw = fs.readFileSync(`${name[0]}.json`); 260 | var abi = JSON.parse(raw); 261 | if (abi["abi"]) { 262 | abi = abi["abi"] 263 | } 264 | 265 | const totalFunction = [] 266 | const totalPublicFunction = [] 267 | const totalExtensionFunction = [] 268 | const totaldefaultFunction = [] 269 | const totalFunctionX = [] 270 | const call = [] 271 | abi.forEach(data => { 272 | // if(data.name == "WETH") { 273 | if(data.type == 'function') { 274 | if(!data.outputs[0]) return 275 | if(!data.stateMutability == "nonpayable") return 276 | const returnType = handleOutput(data.outputs) 277 | call.push(contractCall(name, data.name, returnType, handleInput(data.inputs), data.stateMutability == "view")) 278 | totalFunction.push(defaultProtocolFunction(data.name, returnType, handleInput(data.inputs), data.stateMutability == "view")) 279 | if(data.stateMutability == "view") { 280 | totalPublicFunction.push(defaultPublicFunction(name, data.name, returnType, handleInput(data.inputs))) 281 | }else { 282 | totalPublicFunction.push(defaultPublicPayableFunction(name, data.name, handleInput(data.inputs))) 283 | } 284 | if(data.stateMutability == "view") totalExtensionFunction.push(defaultExtensionFunction(data.name, returnType, handleInput(data.inputs))) 285 | if(data.stateMutability == "view") totaldefaultFunction.push(defaultResponse(data.name, returnType)) 286 | totalFunctionX.push(handleInputFunctionResponse(data.name, handleInput(data.inputs))) 287 | // } 288 | 289 | } 290 | }); 291 | const mains = main(name, totalFunction, totalPublicFunction, totalExtensionFunction, call) 292 | const res = response(name, totaldefaultFunction) 293 | const abiFunc = ABIFunction(name, totalFunctionX) 294 | if (!fs.existsSync(`./${name}`)){ 295 | fs.mkdirSync(`./${name}`); 296 | } 297 | fs.writeFile(`./${name}/${name}.swift`, mains, function (err) { 298 | if (err) throw err; 299 | fs.writeFile(`./${name}/${name}Functions.swift`, abiFunc, function (err) { 300 | if (err) throw err; 301 | fs.writeFile(`./${name}/${name}Responses.swift`, res, function (err) { 302 | if (err) throw err; 303 | console.log('Generate success!'); 304 | }); 305 | }); 306 | }); 307 | } 308 | start() --------------------------------------------------------------------------------