-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Question: how to reference coins as sui_types.Argument when building ProgrammableMoveCall arguments?
Trying to swap coins on Cetus exchange. Reference can be used like this:
argCoin0, _ := ptb.Obj(sui_types.ObjectArg{
ImmOrOwnedObject: coinTypeAdata.Reference(),
})Just using reference directly produces error like this:
Error checking transaction input objects: MutableObjectUsedMoreThanOnce { object_id: 0xbaa475d27182a12a12d18650aab887575afba27f271c434e1614ed0eeabf283c } (this is address of SUI coin object).
Real transactions replace coin references with Result N, can not produce result like this via this SDK.

Usage example:
packageId, _ := sui_types.NewObjectIdFromHex("0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10")
ptb := sui_types.NewProgrammableTransactionBuilder()
argA2b, _ := ptb.Pure(true)
argByAmountIn, _ := ptb.Pure(true)
argAmount, _ := ptb.Pure(100000)
argSqrtPriceLimit, _ := ptb.Pure(bcs.NewUint128FromUint64(4295048016, 0))
argFalse, _ := ptb.Pure(false)
argGlobalConfigId, _ := ptb.Obj(sui_types.ObjectArg{
SharedObject: &struct {
Id sui_types.ObjectID
InitialSharedVersion sui_types.SequenceNumber
Mutable bool
}{
Id: *globalConfigIdObj,
InitialSharedVersion: 1574190,
Mutable: true,
},
})
argPoolAddr, _ := ptb.Obj(sui_types.ObjectArg{
SharedObject: &struct {
Id sui_types.ObjectID
InitialSharedVersion sui_types.SequenceNumber
Mutable bool
}{
Id: *poolObj,
InitialSharedVersion: *poolInShVer,
Mutable: true,
},
})
ptb.Command(
sui_types.Command{
MoveCall: &sui_types.ProgrammableMoveCall{
Package: *packageId,
Module: move_types.Identifier("router"),
Function: move_types.Identifier("swap"),
TypeArguments: []move_types.TypeTag{
{Struct: &move_types.StructTag{Address: *coin1Addr, Module: "usdc", Name: "USDC"}},
{Struct: &move_types.StructTag{Address: *coin2Addr, Module: "sui", Name: "SUI"}},
},
Arguments: []sui_types.Argument{
argGlobalConfigId,
argPoolAddr,
argCoin0, // <-- this
argCoin1, // <-- this
argA2b,
argByAmountIn,
argAmount,
argSqrtPriceLimit,
argFalse,
argClockAddress,
},
},
},
)
pt := ptb.Finish()
tx := sui_types.NewProgrammable(
*wallet, []*sui_types.ObjectRef{coinTypeBdata.Reference()},
pt, 1000000, 1000,
)
txBytes, err := bcs.Marshal(tx)Metadata
Metadata
Assignees
Labels
No labels