|
| 1 | +import Foundation |
| 2 | + |
| 3 | +class OKXDexSwapRequestParameters: NetworkRequestUrlParameters, Decodable { |
| 4 | + /// Chain ID (e.g., 1 for Ethereum) |
| 5 | + let chainId: String |
| 6 | + |
| 7 | + /// The input amount of a token to be sold (set in minimal divisible units, e.g., 1.00 USDT set as 1000000, 1.00 DAI set as 1000000000000000000), you could get the minimal divisible units from https://www.okx.com/api/v5/dex/aggregator/all-tokens |
| 8 | + let amount: String |
| 9 | + |
| 10 | + /// The contract address of a token you want to send (e.g.,0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee) |
| 11 | + let fromTokenAddress: String |
| 12 | + |
| 13 | + /// The contract address of a token you want to receive (e.g.,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48) |
| 14 | + let toTokenAddress: String |
| 15 | + |
| 16 | + /// The slippage you are willing to accept. If you set 0.5, it means 50% slippage is acceptable. min:0 max:1 |
| 17 | + let slippage: String |
| 18 | + |
| 19 | + /// User's wallet address (e.g.,0x3f6a3f57569358a512ccc0e513f171516b0fd42a) |
| 20 | + let userWalletAddress: String |
| 21 | + |
| 22 | + /// Referrer address (Supports SOL or SPL-Token commissions. SOL commissions use wallet address, and SPL-Token commissions use token account.) The fromToken address that receives the commission. When using the API, the fee rate can be adjusted by adding feePercent. Note: This doesn’t support transactions involving wrapped tokens such as those between SOL and WSOL. In a single transaction, either a fromToken commission or a toToken commission can be selected. |
| 23 | + let swapReceiverAddress: String? |
| 24 | + |
| 25 | + /// recipient address of a purchased token if not set, userWalletAddress will receive a purchased token (e.g.,0x3f6a3f57569358a512ccc0e513f171516b0fd42a) |
| 26 | + let referrerAddress: String? |
| 27 | + |
| 28 | + /// The percentage of fromTokenAmount will be sent to the referrer's address, the rest will be set as the input amount to be sold. min percentage:0 max percentage:3 |
| 29 | + let feePercent: String? |
| 30 | + |
| 31 | + /// (Optional, The gas (in wei) for the swap transaction. If the value is too low to achieve the quote, an error will be returned |
| 32 | + let gaslimit: String? |
| 33 | + |
| 34 | + /// (Optional, defaults to average) The target gas price level for the swap transaction,set to average or fast or slow |
| 35 | + let gasLevel: String? |
| 36 | + |
| 37 | + /// DexId of the liquidity pool for limited quotes, multiple combinations separated by , (e.g., 1,50,180, see liquidity list for more) |
| 38 | + let dexIds: String? |
| 39 | + |
| 40 | + /// Account address for toToken in solana transactions, Get method https://www.okx.com/ru/web3/build/docs/waas/dex-use-swap-solana-quick-start |
| 41 | + let solTokenAccountAddress: String? |
| 42 | + |
| 43 | + /// (Optional. The default is 90%.) The percentage (between 0 - 1.0) of the price impact allowed. When the priceImpactProtectionPercentage is set, if the estimated price impact is above the percentage indicated, an error will be returned. For example, if PriceImpactProtectionPercentage = .25 (25%), any quote with a price impact higher than 25% will return an error. This is an optional feature, and the default value is 0.9. When it’s set to 1.0 (100%), the feature will be disabled, which means that every transaction will be allowed to pass. Note: If we’re unable to calculate the price impact, we’ll return null, and the price impact protection will be disabled. |
| 44 | + let priceImpactProtectionPercentage: String? |
| 45 | + |
| 46 | + /// You can customize the parameters to be sent on the blockchain in callData by encoding the data into a 128-character 64-bytes hexadecimal string. For example, the string “0x111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111” needs to keep the “0x” at its start. |
| 47 | + let callDataMemo: String? |
| 48 | + |
| 49 | + /// toToken referrer address (Only supports SPL-Token commissions which use token account.) The toToken address that receives the commission. When using the API, the fee rate can be adjusted by adding feePercent. Note: This doesn’t support transactions involving wrapped tokens such as those between SOL and WSOL. In a single transaction, either a fromToken commission or a toToken commission can be selected. |
| 50 | + let toTokenReferrerAddress: String? |
| 51 | + |
| 52 | + /// Used for transactions on the Solana network and similar to gasPrice on Ethereum. This price determines the priority level of the transaction. The higher the price, the more likely that the transaction can be processed faster. |
| 53 | + let computeUnitPrice: String? |
| 54 | + |
| 55 | + /// Used for transactions on the Solana network and analogous to gasLimit on Ethereum, which ensures that the transaction won’t take too much computing resource. |
| 56 | + let computeUnitLimit: String? |
| 57 | + |
| 58 | + init( |
| 59 | + chainId: String, |
| 60 | + amount: String, |
| 61 | + fromTokenAddress: String, |
| 62 | + toTokenAddress: String, |
| 63 | + slippage: String, |
| 64 | + userWalletAddress: String, |
| 65 | + swapReceiverAddress: String? = nil, |
| 66 | + referrerAddress: String? = nil, |
| 67 | + feePercent: String? = nil, |
| 68 | + gaslimit: String? = nil, |
| 69 | + gasLevel: String? = nil, |
| 70 | + dexIds: String? = nil, |
| 71 | + solTokenAccountAddress: String? = nil, |
| 72 | + priceImpactProtectionPercentage: String? = nil, |
| 73 | + callDataMemo: String? = nil, |
| 74 | + toTokenReferrerAddress: String? = nil, |
| 75 | + computeUnitPrice: String? = nil, |
| 76 | + computeUnitLimit: String? = nil |
| 77 | + ) { |
| 78 | + self.chainId = chainId |
| 79 | + self.amount = amount |
| 80 | + self.fromTokenAddress = fromTokenAddress |
| 81 | + self.toTokenAddress = toTokenAddress |
| 82 | + self.slippage = slippage |
| 83 | + self.userWalletAddress = userWalletAddress |
| 84 | + self.swapReceiverAddress = swapReceiverAddress |
| 85 | + self.referrerAddress = referrerAddress |
| 86 | + self.feePercent = feePercent |
| 87 | + self.gaslimit = gaslimit |
| 88 | + self.gasLevel = gasLevel |
| 89 | + self.dexIds = dexIds |
| 90 | + self.solTokenAccountAddress = solTokenAccountAddress |
| 91 | + self.priceImpactProtectionPercentage = priceImpactProtectionPercentage |
| 92 | + self.callDataMemo = callDataMemo |
| 93 | + self.toTokenReferrerAddress = toTokenReferrerAddress |
| 94 | + self.computeUnitPrice = computeUnitPrice |
| 95 | + self.computeUnitLimit = computeUnitLimit |
| 96 | + } |
| 97 | +} |
0 commit comments