AvaProtocol / OAK-blockchain

OAK(Onchain Autonomous Framework) is a unique blockchain built on Substrate framework with event-driven smart contract VM, autonomous transactions, and on-chain scheduler.
GNU General Public License v3.0
111 stars 73 forks source link

Attempting to compose a SWAP using Turing's automationTime pallet. #531

Open decentration opened 1 month ago

decentration commented 1 month ago

I have attempted to compose a tx that that dispatches an xcm task at a later time, which executes a swap call on the mangata chain.

Because there is no prior example of a swap tx executed with automationTime pallet i am finding it difficult to compose the correct call.

For fast checking here is the decoded call data:

0x3c01000410f10f67000000000301030009210100f2529946850f8dd66c794a795a6b01a911f25df007e4cf5f97f38a037380f250040d0300000300004b29f079000000000000000000000000ac0d0208040000000000000000d0ed902e0000000000000000000000b528e8550182e3728703000000000000113a03b7dd2cad113a03b7c6d1e20000

you can decode this easily in the decode section of PJS Apps extrinsics:

Screenshot 2024-10-17 at 22 52 45

The encoded call data is swap call on mangata...

0x0d0208040000000000000000d0ed902e0000000000000000000000b528e8550182e3728703000000000000

This TX executes on Turing but when when executing the xcm task it throws a generic error from xcmpHandler.

decentration commented 1 month ago

ok good news, we managed to execute the xcm task which reached mangata, however we have a weight issue:

Screenshot 2024-10-23 at 15 07 10

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.mangata.online#/explorer/query/0x5691e78053542c9623f35c0acb516dfd128f3c977f9dd0e588081df5d247d6aa

here is the updated call data:

0x3c010004600119670000000001010100f9200100000100004b29f0790000000000000000000000003d010500009649b7c292d18ec76b166979d7047f9a6987936a69b43e3a007e235a4d3a253a01000d01040000000000000000d0ed902e0000000000000000000000b528e8550182e3728703000000000000113a03b7dd2cad113a03b7c6d1e20000

imstar15 commented 1 month ago

Hi @decentration

I schedule a task to call xyk.multiswapSellAsset by xcm-demo, branch charles-swap_asset.

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fturing-rpc.dwellir.com#/explorer/query/0x206ce3b475ced392241808ef3f4d1c6e7c0c342058384ffead4c617c9ce4320b

put you exported private key in private folder

PASS_PHRASE=<PASS_PHRASE> yarn run mangata-kusama

encoded code:

0x3c01000840c619670000000098c819670000000003010100f9200301010009210301010009216a4cb29800000000000000000000000041010500003830ef2fdb02d711afe91c830737375e32ac9904886266897f361b5a2ec13a3901000d0208070000000000000000ca9a3b0000000000000000000000000100000000000000000000000000000003dcb263e6894907dc9b081c0189490000

My weight:

image

Your weight:

image

Task executed:

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fturing-rpc.dwellir.com#/explorer/query/5912758

Please compare your weight calculation with xcm-demo.

But Mangata do not allow proxy to execute xyk.multiswapSellAsset.

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-archive.mangata.online#/explorer/query/5918821

There's only AutoCompund type in Mangata's proxy type list.

image

decentration commented 1 month ago

hey Charles @imstar15 thanks for this!

So just so i understand the flow, proxy is a necessary part of the process, and we need to allow multiswapSellAsset as part of their proxy type? just to confirm proxy is required in the process, and its a one time thing if it was added to the proxy type list.

Maybe we can do this by using forceProxyType? I will try this now. But actually this doesnt fit the flow because one has to hard code the exact swap.

Screenshot 2024-10-24 at 10 10 03

if we cant, then will need to wait for mangata to add "Swap" to their proxy types.

imstar15 commented 1 month ago

I have try your solution.

I schedule task to call xyk.multiswapSellAsset by proxy with the undefined forceProxyType param.

const compoundRewardsExtrinsic = mangataApi.tx.xyk.multiswapSellAsset([7, 0], '1000000000', '1');
        const taskPayloadExtrinsic = mangataApi.tx.proxy.proxy(u8aToHex(keyringPair.addressRaw), undefined, compoundRewardsExtrinsic);

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-archive.mangata.online#/explorer/query/0xf0f2737e1438200edba3bc54331ee3bd7fbeabaa9d1c2c7adb0feaef2185909a

The proxy.proxy is not executed.

I think we need to wait for mangata to add "Swap" to their proxy types.

@decentration

flipchan commented 1 month ago

I think we need to wait for mangata to add "Swap" to their proxy types.

Thanks for a great response @imstar15 , I was scratching my head trying to wrap the proxy call in a polkadotxcm.send tx, the bottleneck here is managatax chain, so other supported proxy types on other connected chains should potentially work than.

github-actions[bot] commented 4 days ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.