MCPcopy Create free account
hub / github.com/MystenLabs/capybot / buildInputCoinForAmount

Function buildInputCoinForAmount

src/utils/utils.ts:203–241  ·  view source on GitHub ↗
(
  txb: TransactionBlock,
  amount: bigint,
  coinType: string,
  owner: SuiAddress,
  provider: JsonRpcProvider
)

Source from the content-addressed store, hash-verified

201}
202
203export 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
243function selectCoinObjectIdGreaterThanOrEqual(
244 coins: CoinAsset[],

Callers 2

createSwapTransactionMethod · 0.90

Calls 3

isSUIFunction · 0.85
selectTradeCoinsFunction · 0.85

Tested by

no test coverage detected