( txb: TransactionBlock, amount: bigint, coinType: string, owner: SuiAddress, provider: JsonRpcProvider )
| 201 | } |
| 202 | |
| 203 | export async function buildInputCoinForAmount( |
| 204 | txb: TransactionBlock, |
| 205 | amount: bigint, |
| 206 | coinType: string, |
| 207 | owner: SuiAddress, |
| 208 | provider: JsonRpcProvider |
| 209 | ): Promise<TransactionArgument[] | undefined> { |
| 210 | if (amount === BigInt(0)) { |
| 211 | throw new Error(`The amount cannot be (${amount})`); |
| 212 | } |
| 213 | |
| 214 | const totalBalance = await getTotalBalanceByCoinType( |
| 215 | provider, |
| 216 | owner, |
| 217 | coinType |
| 218 | ); |
| 219 | |
| 220 | if (BigInt(totalBalance) < amount) { |
| 221 | // throw new Error(`The amount(${totalBalance}) is Insufficient balance for ${coinType} , expect ${amount}`); |
| 222 | console.log( |
| 223 | `The amount(${totalBalance}) is Insufficient balance for ${coinType} , expect ${amount}` |
| 224 | ); |
| 225 | return undefined; |
| 226 | } |
| 227 | |
| 228 | if (isSUI(coinType)) { |
| 229 | console.log(`coinType: (${coinType}), amount: (${amount})`); |
| 230 | return [txb.splitCoins(txb.gas, [txb.pure(amount)])[0]!]; |
| 231 | } |
| 232 | |
| 233 | const coinObjectIds = await selectTradeCoins( |
| 234 | provider, |
| 235 | owner, |
| 236 | coinType, |
| 237 | new Decimal(Number(amount)) |
| 238 | ); |
| 239 | console.log(`coinObjectIds: ${coinObjectIds}`); |
| 240 | return coinObjectIds.map((id) => txb.object(id)); |
| 241 | } |
| 242 | |
| 243 | function selectCoinObjectIdGreaterThanOrEqual( |
| 244 | coins: CoinAsset[], |
no test coverage detected