diff --git a/Sources/Solidity/ABIType.swift b/Sources/Solidity/ABIType.swift index 3427a75..7543f89 100644 --- a/Sources/Solidity/ABIType.swift +++ b/Sources/Solidity/ABIType.swift @@ -72,11 +72,16 @@ public indirect enum ABIType: Equatable, CustomStringConvertible { case .dynamicBytes: return "bytes" case .string: - return "bytes" + return "string" case .dynamicArray(let type): return "\(type)[]" case .tuple(let types): - return types.reduce("", { $0 + $1.description }) + var typeString = "(" + for type in types { + typeString.append(type.description + ",") + } + typeString.removeLast() + return typeString + ")" } } } diff --git a/Sources/Solidity/ABIValue.swift b/Sources/Solidity/ABIValue.swift index 6a1d281..863432c 100644 --- a/Sources/Solidity/ABIValue.swift +++ b/Sources/Solidity/ABIValue.swift @@ -96,7 +96,17 @@ public indirect enum ABIValue { let dataLength = string.data(using: .utf8)?.count ?? 0 return 32 + ((dataLength + 31) / 32) * 32 case .dynamicArray(_, let array): - return 32 + array.reduce(0, { $0 + $1.length }) + var isDynamic = true + for item in array { + if !item.isDynamic { + isDynamic = false + } + } + if isDynamic { + return 32 + (array.count * 32) + array.reduce(0, { $0 + $1.length }) + } else { + return 32 + array.reduce(0, { $0 + $1.length }) + } case .tuple(let array): return array.reduce(0, { $0 + $1.length }) } diff --git a/Sources/Solidity/ERC20Encoder.swift b/Sources/Solidity/ERC20Encoder.swift index b0de8ae..6d999e8 100644 --- a/Sources/Solidity/ERC20Encoder.swift +++ b/Sources/Solidity/ERC20Encoder.swift @@ -239,4 +239,30 @@ public final class ERC20Encoder { try! encoder.encode(function: function, arguments: [tokensBought, maxTokensSold, maxTrxSold, deadline, tokenAddr]) return encoder.data } + + /// Encodes a function call to `queryDIDAddress` + /// + /// Solidity function: `function queryDIDAddress(String did) public returns (address);` + public static func encodeQueryDIDAddress(did: String) -> Data { + let function = Function(name: "queryAddress", parameters: [.string]) + let encoder = ABIEncoder() + try! encoder.encode(function: function, arguments: [did]) + return encoder.data + } + + /// Swap V3 + public static func encodeSwapExactInput(path: [Address], + poolVersion: [String], + versionLen: [BigUInt], + fees: [BigUInt], + tuple: [Any]) -> Data { + let function = Function(name: "swapExactInput", parameters: [.dynamicArray(.address), + .dynamicArray(.string), + .dynamicArray(.uint(bits: 256)), + .dynamicArray(.uint(bits: 24)), + .tuple([.uint(bits: 256), .uint(bits: 256), .address, .uint(bits: 256)])]) + let encoder = ABIEncoder() + try! encoder.encode(function: function, arguments: [path, poolVersion, versionLen, fees, tuple]) + return encoder.data + } }