What's New

1.0.4

2022-09-01T15:33:52Z

What's Changed

Full Changelog: 1.0.3...1.0.4

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 response = await exchange.swap(blockchain: .polygon,
                                       parameters: SwapParameters(fromTokenAddress: fromAddress,
                                                                  toTokenAddress: toAddress,
                                                                  amount: "\(amount)",
                                                                  fromAddress: fromAddress,
                                                                  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: Sun Sep 04 2022 17:44:30 GMT-0500 (GMT-05:00)