Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set a objectid ("Mutable", bool), Mutable = False? #104

Closed
jiangdydy opened this issue May 5, 2023 · 17 comments
Closed

How to set a objectid ("Mutable", bool), Mutable = False? #104

jiangdydy opened this issue May 5, 2023 · 17 comments

Comments

@jiangdydy
Copy link

I get ImmutableParameterExpectedError when I am execute a move_call.
arguments=[
# SuiU64("100"),
ObjectID("0x0000000000000000000000000000000000000000000000000000000000000006"),
ObjectID("0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2"),
net,
SuiU64("0"),
],
And I run print(txn.builder.finish_for_inspect()).

    "Object": {
      "SharedObject": {
        "ObjectID": {
          "Address": "0000000000000000000000000000000000000000000000000000000000000006"
        },
        "SequenceNumber": 1,
        "Mutable": true
      }
    }
  },

But Mutable should be False, how can I change it?

@jiangdydy
Copy link
Author

@FrankC01 Thank you very much if you can help me

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

What network
Show me the source code for your call and the full output with the error

What is the signature of function you are calling?

I verified that both the Clock and your second argument and they are marked "mutable" true in mainnet

@jiangdydy
Copy link
Author

jiangdydy commented May 5, 2023

here is the soucre code

txn = SuiTransaction(client=provider)
net = Argument("NestedResult",(0,0))
txn.split_coin(coin=Argument("GasCoin"), amounts=[100])
swap_tx = txn.move_call(
    target="0xec38920815116f74c344f3e0497e9073f9f88b9f2bd2505284bb5f9d46cea200::interface::swap_with_point",
    arguments=[
        ObjectID("0x0000000000000000000000000000000000000000000000000000000000000006"),
        ObjectID("0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2"),
        net,
        SuiU64("0"),
    ],
    type_arguments=[
        "0x2::sui::SUI",
        "0x83e6571118eaca12d7d428ae06341a8063711bc9983e0d6cefb3790a26b9d62c::SDOGE::SDOGE"
    ],
)
tx_result = txn.execute(gas_budget="1000000000")
if tx_result.is_ok():
    print(tx_result.result_data.to_json())
    print(tx_result.result_data.to_json(indent=2))
else:
    print(tx_result.result_string)

here is the error

{'code': -32000, 'message': 'Transaction has non recoverable errors from at least 1/3 of validators: [(UserInputError { error: ImmutableParameterExpectedError { object_id: 0x0000000000000000000000000000000000000000000000000000000000000006 } }, 3651, [k#a6d0377c.., k#ade9aeca.., k#8f116bc5.., k#b6461b9b.., k#937e5f97.., k#aee07fa8.., k#8e0f0d43.., k#8ac21706.., k#80771cda.., k#b267c223.., k#8b463f2a.., k#b7530790.., k#b33ef2fe.., k#92fdafba.., k#a3e5d733.., k#8c0dcf63.., k#aa247346.., k#a4c899c1.., k#a5bd06fd.., k#80d86418.., k#aefd3760.., k#b51b2f0b.., k#80fa69b7.., k#a8c262ab.., k#b0ce3137.., k#8501c121.., k#ab6808a1.., k#97d0d05b.., k#a42396c5.., k#969d1802.., k#905d9f4b..]), (RpcError("error trying to connect: deadline has elapsed", "The service is currently unavailable"), 172, [k#a36683ae.., k#b4fd27a3.., k#b3ab4654.., k#b4f5d522..])].'}

I want to use this code to buy token.
It seems that Mutable of Object(0x6) should be flase ,But I dont know how to set it.

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

To start with, explicitly setting/using Argument() is invalid. So these should not be done:

Argument("NestedResult",(0,0))
Argument("GasCoin")

Instead of txn.execute(....)

Use this and then put the results in a comment below:

    inspect_result: TxInspectionResult = txn.inspect_all()
    if inspect_result:
        print(f"Gas total: {inspect_result.effects.gas_used.total}", end="")
        print(f" after rebate: {inspect_result.effects.gas_used.total_after_rebate}")
        print(inspect_result.to_json(indent=2))
    else:
        print("Inspection failed!")

@jiangdydy
Copy link
Author

jiangdydy commented May 5, 2023

Here is the output.

Gas total: 23250260 after rebate: 15989600
{
  "effects": {
    "status": {
      "status": "success",
      "error": null,
      "succeeded": true
    },
    "messageVersion": "v1",
    "gasUsed": {
      "computationCost": "5000000",
      "storageCost": "10989600",
      "storageRebate": "7260660"
    },
    "transactionDigest": "EFJV55zyqNM22AxwEUTbFpFcSd4khLDqd45LdWwM7gSn",
    "gasObject": {
      "reference": {
        "objectId": "0xabf719733bc1179c7bf262de25b07f8599c59d2469f1cac2bd0fa6d77da6541f",
        "version": 9223372036854775807,
        "digest": "5LhisUnFivPbaFCS1bQJZQErWJ9gMBPMM2ERxLn4YEz1"
      },
      "owner": "0x7a9385fb05440bf3a2839a421ea9dbb243df5b3c524975c850676045ff2e96be"
    },
    "modifiedAtVersions": [
      {
        "objectId": "0x0000000000000000000000000000000000000000000000000000000000000006",
        "sequenceNumber": "1727253"
      },
      {
        "objectId": "0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2",
        "sequenceNumber": "1817483"
      },
      {
        "objectId": "0xabf719733bc1179c7bf262de25b07f8599c59d2469f1cac2bd0fa6d77da6541f",
        "sequenceNumber": "0"
      },
      {
        "objectId": "0xb80dfb0456a58e5ff7409b42a4caa44e0240a9a69e305a0d2cbfb3f7af222cd2",
        "sequenceNumber": "1817469"
      }
    ],
    "dependencies": [
      "68GHt12iRjQZxitretCsJ4skwmUjeDxWSJqjWUVxPPj8",
      "7ySnA7ojqidLcwNJtCtvPRPENGFWTM2qUNfudFq8fJ6G",
      "AYVEb4ooK9SGLJoXGDuUboSob9nahqFX9pEpS9qjGPqj",
      "DMwfDqZjg9LhyCviidZM3zEm9dBg8Z8kmWiLjwaVLzas",
      "HzRTGc8KzEGSjm7TAVb2DWe2eT5ZHcdFSjW1jWNxhBRr"
    ],
    "mutated": [
      {
        "reference": {
          "objectId": "0x0000000000000000000000000000000000000000000000000000000000000006",
          "version": 9223372036854775807,
          "digest": "A5wTe89QDpN2jXuo8nVmHuXPzF4q9sYkgQYwvYp8mrmM"
        },
        "owner": {
          "initial_shared_version": 1
        }
      },
      {
        "reference": {
          "objectId": "0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2",
          "version": 9223372036854775807,
          "digest": "CqBj3eC1qNM1a7AF2qmT2UT4U7e5RduQ4Cmkzvx6uEEY"
        },
        "owner": {
          "initial_shared_version": 54
        }
      },
      {
        "reference": {
          "objectId": "0xabf719733bc1179c7bf262de25b07f8599c59d2469f1cac2bd0fa6d77da6541f",
          "version": 9223372036854775807,
          "digest": "5LhisUnFivPbaFCS1bQJZQErWJ9gMBPMM2ERxLn4YEz1"
        },
        "owner": "0x7a9385fb05440bf3a2839a421ea9dbb243df5b3c524975c850676045ff2e96be"
      },
      {
        "reference": {
          "objectId": "0xb80dfb0456a58e5ff7409b42a4caa44e0240a9a69e305a0d2cbfb3f7af222cd2",
          "version": 9223372036854775807,
          "digest": "8ngttSkbCRhtiH5aRsqXB71oi3nz18Qj5NTSQqFVTQPj"
        },
        "owner": "0x6edec171d3b4c6669ac748f6de77f78635b72aac071732b184677db19eefd9e8"
      }
    ],
    "created": [
      {
        "reference": {
          "objectId": "0x9da29a4bfe4f96cc78829ea378155573c0fd82ced82c76427de9808c5a3a516a",
          "version": 9223372036854775807,
          "digest": "9ydZVo2EdNbXgFGt2ioRSWCp49DQorf2pgzJ1CPUWkWy"
        },
        "owner": "0x7a9385fb05440bf3a2839a421ea9dbb243df5b3c524975c850676045ff2e96be"
      }
    ],
    "deleted": [],
    "wrapped": [],
    "unwrapped": [],
    "unwrappedThenDeleted": [],
    "sharedObjects": [
      {
        "objectId": "0x0000000000000000000000000000000000000000000000000000000000000006",
        "version": 1727253,
        "digest": "3NcdSRDxpy7sbS6rna8HZJRvM4LRxCxEXutaCKmk5hhd"
      },
      {
        "objectId": "0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2",
        "version": 1817483,
        "digest": "5XrxYPBxpwXjwznFSTQ532ScfUKk5xuTdbqP282EQdKj"
      }
    ],
    "executedEpoch": "22",
    "eventsDigest": "KwUSCaxfSJ9yBaGQQ4fZP4UD2oe2EgYQHtf4GrAVGL3"
  },
  "events": [
    {
      "bcs": "PURJbnM6dQfKVSNPMfhYQgJVMJBZT5M9UFR5UQUtGD6eYh1eazFQqQFAUdHwgc8UgCTdf1k17amqjDvMbWFvLYBdvS87CKCuHpnypEUkU2EPqneWkPzybad9PQwdtTbrRZQgrhS3dLvi1oBkAuf6mBxcSZtwGiuwCeN8M3QT5YexbbinLtQ5KnSuNbuuDZ2Mi8WaWi4xju9khxf199pPUGUfw57qRJmQFNgxJq2pGtiZhjy8J3NFi9YcrHNaRSoSJN9r2rGCJgFnLJn9aBYtsJneoZGfWm6kxPY7hJRjT7XTAoZ",
      "packageId": "0x6b84da4f5dc051759382e60352377fea9d59bc6ec92dc60e0b6387e05274415f",
      "parsedJson": {
        "coin_x_in": "100",
        "coin_x_out": "0",
        "coin_y_in": "0",
        "coin_y_out": "716",
        "global": "0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2",
        "lp_name": "LP-0000000000000000000000000000000000000000000000000000000000000002::sui::SUI-83e6571118eaca12d7d428ae06341a8063711bc9983e0d6cefb3790a26b9d62c::SDOGE::SDOGE"
      },
      "sender": "0x7a9385fb05440bf3a2839a421ea9dbb243df5b3c524975c850676045ff2e96be",
      "transactionModule": "interface",
      "type": "0x6b84da4f5dc051759382e60352377fea9d59bc6ec92dc60e0b6387e05274415f::event::SwappedEvent",
      "id": {
        "txDigest": "EFJV55zyqNM22AxwEUTbFpFcSd4khLDqd45LdWwM7gSn",
        "eventSeq": "0"
      },
      "timestampMs": ""
    }
  ],
  "results": [
    {
      "mutableReferenceOutputs": [
        [
          "GasCoin",
          [
            171,
            247,
            25,
            115,
            59,
            193,
            23,
            156,
            123,
            242,
            98,
            222,
            37,
            176,
            127,
            133,
            153,
            197,
            157,
            36,
            105,
            241,
            202,
            194,
            189,
            15,
            166,
            215,
            125,
            166,
            84,
            31,
            156,
            115,
            59,
            164,
            11,
            0,
            0,
            0
          ],
          "0x2::coin::Coin<0x2::sui::SUI>"
        ]
      ],
      "returnValues": [
        [
          [
            25,
            231,
            210,
            237,
            168,
            228,
            244,
            147,
            227,
            215,
            181,
            183,
            89,
            168,
            164,
            214,
            155,
            55,
            233,
            141,
            248,
            204,
            231,
            109,
            151,
            31,
            19,
            113,
            225,
            41,
            186,
            186,
            100,
            0,
            0,
            0,
            0,
            0,
            0,
            0
          ],
          "0x2::coin::Coin<0x2::sui::SUI>"
        ]
      ]
    },
    {
      "mutableReferenceOutputs": [
        [
          {
            "Input": 2
          },
          [
            48,
            131,
            227,
            215,
            81,
            54,
            12,
            144,
            132,
            186,
            51,
            246,
            217,
            225,
            173,
            56,
            251,
            42,
            17,
            207,
            252,
            21,
            31,
            46,
            228,
            165,
            192,
            61,
            166,
            31,
            177,
            226,
            0,
            65,
            219,
            119,
            135,
            78,
            208,
            143,
            153,
            151,
            237,
            0,
            119,
            10,
            44,
            176,
            202,
            131,
            170,
            59,
            129,
            211,
            165,
            3,
            48,
            205,
            128,
            146,
            55,
            187,
            215,
            101,
            83,
            65,
            219,
            119,
            135,
            78,
            208,
            143,
            153,
            151,
            237,
            0,
            119,
            10,
            44,
            176,
            202,
            131,
            170,
            59,
            129,
            211,
            165,
            3,
            48,
            205,
            128,
            146,
            55,
            187,
            215,
            101,
            83,
            110,
            222,
            193,
            113,
            211,
            180,
            198,
            102,
            154,
            199,
            72,
            246,
            222,
            119,
            247,
            134,
            53,
            183,
            42,
            172,
            7,
            23,
            50,
            177,
            132,
            103,
            125,
            177,
            158,
            239,
            217,
            232,
            23,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            44,
            224,
            238,
            31,
            91,
            61,
            48,
            214,
            37,
            129,
            81,
            149,
            37,
            148,
            240,
            30,
            125,
            65,
            207,
            74,
            9,
            6,
            32,
            213,
            124,
            24,
            59,
            20,
            144,
            194,
            213,
            29,
            58,
            42,
            0,
            0,
            0,
            0,
            0,
            0,
            195,
            227,
            8,
            0,
            0,
            0,
            0,
            0,
            146,
            50,
            73,
            251,
            157,
            144,
            19,
            89,
            227,
            32,
            155,
            185,
            87,
            240,
            24,
            90,
            24,
            236,
            79,
            86,
            196,
            98,
            130,
            69,
            48,
            216,
            189,
            220,
            235,
            67,
            108,
            18,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0
          ],
          "0x6b84da4f5dc051759382e60352377fea9d59bc6ec92dc60e0b6387e05274415f::implements::Global"
        ]
      ]
    }
  ],
  "error": ""
}

It seems the code can work but I cant sent it out.

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

Sorry, could you also add this before the inspect and add in comment below?

print(txn.raw_kind().to_json(indent=2))

@jiangdydy
Copy link
Author

jiangdydy commented May 5, 2023

Ok,here is the output.

{
  "ProgrammableTransaction": {
    "Inputs": [
      {
        "Pure": "6400000000000000"
      },
      {
        "Object": {
          "SharedObject": {
            "ObjectID": {
              "Address": "0000000000000000000000000000000000000000000000000000000000000006"
            },
            "SequenceNumber": 1,
            "Mutable": true
          }
        }
      },
      {
        "Object": {
          "SharedObject": {
            "ObjectID": {
              "Address": "3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2"
            },
            "SequenceNumber": 54,
            "Mutable": true
          }
        }
      },
      {
        "Pure": "0000000000000000"
      }
    ],
    "Command": [
      {
        "SplitCoin": {
          "FromCoin": "GasCoin",
          "Amount": [
            {
              "Input": 0
            }
          ]
        }
      },
      {
        "MoveCall": {
          "Package": {
            "Address": "ec38920815116f74c344f3e0497e9073f9f88b9f2bd2505284bb5f9d46cea200"
          },
          "Module": "interface",
          "Function": "swap_with_point",
          "Type_Arguments": [
            {
              "Struct": {
                "address": {
                  "Address": "0000000000000000000000000000000000000000000000000000000000000002"
                },
                "module": "sui",
                "name": "SUI",
                "type_parameters": []
              }
            },
            {
              "Struct": {
                "address": {
                  "Address": "83e6571118eaca12d7d428ae06341a8063711bc9983e0d6cefb3790a26b9d62c"
                },
                "module": "SDOGE",
                "name": "SDOGE",
                "type_parameters": []
              }
            }
          ],
          "Arguments": [
            {
              "Input": 1
            },
            {
              "Input": 2
            },
            {
              "NestedResult": [
                0,
                0
              ]
            },
            {
              "Input": 3
            }
          ]
        }
      }
    ]
  }
}

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

Right so notice that Input 0 has no value because that Argument("GasCoin") has no value.

We are working on an enhancement to be able to do something like txn.split_coin(txn.gas,...) but it is not there yet: #106

So, in the short term, you could specify an exact coin ID as in:

    swap_tx = txn.move_call(
        target="0xec38920815116f74c344f3e0497e9073f9f88b9f2bd2505284bb5f9d46cea200::interface::swap_with_point",
        arguments=[
            ObjectID("0x0000000000000000000000000000000000000000000000000000000000000006"),
            ObjectID("0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2"),
            ObjectID("0xSOME_COIN_ID"), # <- Specify and actual Coin id here
            SuiU64("0"),
        ],
        type_arguments=[
            "0x2::sui::SUI",
            "0x83e6571118eaca12d7d428ae06341a8063711bc9983e0d6cefb3790a26b9d62c::SDOGE::SDOGE",
        ],
    )
Note the third argument change and comment.

This would also eliminate the `txn.split_coin(...)` you have 

@jiangdydy
Copy link
Author

jiangdydy commented May 5, 2023

Sorry that I can not understand how to fix it...
I want to buy token like this.
https://suiscan.xyz/mainnet/tx/5HMa3e5vFVpns356Eq4kf2PYCkqCXQBjKqNTXwdXbFZR
The arguments seems like to be:

"arguments":[4 items
0:{1 item
"Input":int1
}
1:{1 item
"Input":int2
}
2:{1 item
"NestedResult":[2 items
0:int0
1:int0
]
}
3:{1 item
"Input":int3
}
]

And my code can work when I usding another swap by similar code.

https://suiscan.xyz/mainnet/tx/773CJYEHwRYDcCQgmATJVUDh27bX4tHGCGxsCCzRtehr

net = Argument("NestedResult",(0,0))
txn.split_coin(coin=Argument("GasCoin"), amounts=[100])
swap_tx = txn.move_call(
    target="0xb24b6789e088b876afabca733bed2299fbc9e2d6369be4d1acfa17d8145454d9::router::swap_exact_input",
    arguments=[
        SuiU64("100"),
        net, 
        SuiU64("0"),
        ObjectID("0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"),

    ],
    type_arguments=[
        "0x2::sui::SUI",
        "0xd9f9b0b4f35276eecd1eea6985bfabe2a2bbd5575f9adb9162ccbdb4ddebde7f::smove::SMOVE"
    ],
)

The different between this two swap is that the second one dont need to sent Object(0x64)

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

Again, doing this

net = Argument("NestedResult",(0,0))
txn.split_coin(coin=Argument("GasCoin"), amounts=[100])

In your code is the issue...

@jiangdydy
Copy link
Author

Ok, I am sorry that I still dont konw how to input a NestedResult and how to split_coin.
Maybe the code should be
txn.split_coin(coin='',amounts=[100]),
and
ObjectID("0xSOME_COIN_ID"), # <- Specify and actual Coin id here?
But I am sorry I dont know how to get this parameter.

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

Try this instead:

   coin = txn.split_coin(coin=Argument("GasCoin"), amounts=[100])
   swap_tx = txn.move_call(
        target="0xec38920815116f74c344f3e0497e9073f9f88b9f2bd2505284bb5f9d46cea200::interface::swap_with_point",
        arguments=[
            ObjectID("0x0000000000000000000000000000000000000000000000000000000000000006"),
            ObjectID("0x3083e3d751360c9084ba33f6d9e1ad38fb2a11cffc151f2ee4a5c03da61fb1e2"),
            coin,
            SuiU64("0"),
        ],
        type_arguments=[
            "0x2::sui::SUI",
            "0x83e6571118eaca12d7d428ae06341a8063711bc9983e0d6cefb3790a26b9d62c::SDOGE::SDOGE",
        ],
    )
    ```

@jiangdydy
Copy link
Author

I try it and also get this error.

{'code': -32000, 'message': 'Transaction has non recoverable errors from at least 1/3 of validators: [(RpcError("error trying to connect: deadline has elapsed", "The service is currently unavailable"), 172, [k#b4fd27a3.., k#a36683ae.., k#b4f5d522.., k#b3ab4654..]), (UserInputError { error: ImmutableParameterExpectedError { object_id: 0x0000000000000000000000000000000000000000000000000000000000000006 } }, 3651, [k#ade9aeca.., k#8f116bc5.., k#a6d0377c.., k#b6461b9b.., k#937e5f97.., k#aee07fa8.., k#8e0f0d43.., k#8ac21706.., k#80771cda.., k#b7530790.., k#b267c223.., k#b33ef2fe.., k#8b463f2a.., k#92fdafba.., k#aa247346.., k#80d86418.., k#8c0dcf63.., k#b51b2f0b.., k#a3e5d733.., k#a5bd06fd.., k#a4c899c1.., k#aefd3760.., k#b0ce3137.., k#8501c121.., k#80fa69b7.., k#a8c262ab.., k#97d0d05b.., k#ab6808a1.., k#a42396c5.., k#969d1802.., k#905d9f4b..])].'}

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

Ok, this issue is not with the gas but with the Clock argument. The swap_with_point exepects a &Clock argument which is an immutable reference. But the logic in pysui finds that the clock is marked as mutable.

I need to take this up with MystenLab and should resolve hopefully today.

@FrankC01
Copy link
Owner

FrankC01 commented May 5, 2023

I did a local change in the SDK and seems to be working. Just waiting for Mysten (Sui) to confirm the logic.

Thank you for your patience.

@jiangdydy
Copy link
Author

Thanks a lot for your help!

@FrankC01
Copy link
Owner

FrankC01 commented May 6, 2023

Pushed update 0.20.2 (to PyPi as well)

@FrankC01 FrankC01 closed this as completed May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants