1- import { array , boolean , Infer , integer , object , string , union } from 'superstruct' ;
2- import { normalizeSuiAddress , ObjectId , SharedObjectRef , SuiObjectRef } from '../types' ;
1+ import { any , array , boolean , Infer , integer , object , string , union } from 'superstruct' ;
2+ import { normalizeSuiAddress , ObjectId , SharedObjectRef , SuiObjectRef , TypeTag } from '../types' ;
33import { builder } from './bcs' ;
44
55const ObjectArg = union ( [
@@ -15,10 +15,17 @@ const ObjectArg = union([
1515
1616export const PureCallArg = object ( { Pure : array ( integer ( ) ) } ) ;
1717export const ObjectCallArg = object ( { Object : ObjectArg } ) ;
18+ export const BalanceWithdrawalCallArg = object ( {
19+ BalanceWithdrawal : object ( {
20+ amount : any ( ) ,
21+ type_ : any ( ) ,
22+ } ) ,
23+ } ) ;
1824export type PureCallArg = Infer < typeof PureCallArg > ;
1925export type ObjectCallArg = Infer < typeof ObjectCallArg > ;
26+ export type BalanceWithdrawalCallArg = Infer < typeof BalanceWithdrawalCallArg > ;
2027
21- export const BuilderCallArg = union ( [ PureCallArg , ObjectCallArg ] ) ;
28+ export const BuilderCallArg = union ( [ PureCallArg , ObjectCallArg , BalanceWithdrawalCallArg ] ) ;
2229export type BuilderCallArg = Infer < typeof BuilderCallArg > ;
2330
2431export const Inputs = {
@@ -33,12 +40,27 @@ export const Inputs = {
3340 SharedObjectRef ( ref : SharedObjectRef ) : ObjectCallArg {
3441 return { Object : { Shared : ref } } ;
3542 } ,
43+ /**
44+ * Create a BalanceWithdrawal CallArg that withdraws `amount` from the sender's
45+ * address balance at execution time. Use with `0x2::coin::redeem_funds` to
46+ * convert the withdrawal into a `Coin<T>` object.
47+ *
48+ * @param amount - amount in base units (MIST for SUI)
49+ * @param type_ - the TypeTag of the coin (defaults to SUI)
50+ */
51+ BalanceWithdrawal ( amount : bigint | number , type_ : TypeTag ) : BalanceWithdrawalCallArg {
52+ return { BalanceWithdrawal : { amount, type_ } } ;
53+ } ,
3654} ;
3755
38- export function getIdFromCallArg ( arg : ObjectId | ObjectCallArg ) : string {
56+ export function getIdFromCallArg ( arg : ObjectId | ObjectCallArg | BalanceWithdrawalCallArg ) : string {
3957 if ( typeof arg === 'string' ) {
4058 return normalizeSuiAddress ( arg ) ;
4159 }
60+ if ( 'BalanceWithdrawal' in arg ) {
61+ // BalanceWithdrawal inputs have no object ID; they cannot be deduplicated by ID
62+ return '' ;
63+ }
4264 if ( 'ImmOrOwned' in arg . Object ) {
4365 return arg . Object . ImmOrOwned . objectId ;
4466 }
0 commit comments