What's New

1.0.10

2022-10-21T14:02:55Z

Full Changelog: 1.0.9...1.0.10

Exchange

1Inch exchange api wrapper with async/await swift.

let exchangeFacade: ExchangeFacade = ExchangeService()

// Get tokens info
Task { 
    let tokens = await exchangeFacade.tokens(blockchain: .polygon)
    switch tokens {
    case .success(let tokensDTO):
        dto.tokens.forEach {
            print($0.value)
        }
    case .failure(let error):
        print(error.localizedDescription)
    }
}

// Generation swap data
Task { 
    let amount = 1_000_000_000_000_000_000
    let fromAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
    let toAddress = "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063"
    let walletAddress = "0x**..." //Your wallet address
    
    let response = await exchange.swap(blockchain: .polygon,
                                       parameters: SwapParameters(fromTokenAddress: fromAddress,
                                                                  toTokenAddress: toAddress,
                                                                  amount: "\(amount)",
                                                                  fromAddress: walletAddress,
                                                                  slippage: 1))
    switch response {
    case .success(let dto):
        print(dto.tx.data) // Data for sign and push to blockchain
    case .failure(let error):
        print(error)
    }
}

Supports Ethereum, Binance smart chain, Polygon, Optimism, Arbitrum, Gnosis, Avalanche, Fantom, Klayth, Aurora.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 11:34:48 GMT-0900 (Hawaii-Aleutian Daylight Time)