Skip to content

Commit

Permalink
Update Mangata runtime 3001 (#75)
Browse files Browse the repository at this point in the history
1. Modify feePerSecond in config/mangata-dev.js
2. Remove `providedId` in scheduleXcmpTask interface in
src/mangata/mangata.js
3. Update the version of Mangata-node to v0.30.1. The updated code for
OAK-blockchain hasn't generated a release yet. I will update it later.

Log:
```
Start to schedule an auto-compound call via XCM ...
encodedMangataProxyCall:  0x050000d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01000d080800000064000000
mangataProxyCallFees:  {
  weight: { refTime: '2,905,398,711', proofSize: '3,716' },
  class: 'Normal',
  partialFee: '27.0780 MGRL'
}

1. Create the call for scheduleXcmpTask 
? Select an action to perform Execute immediately
xcmpCall:  0x3c020004000000000000000003010100f9200300000300007484a6c5000000000000000000000000bc050000d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01000d08080000006400000003b7dd2cad113a03b7c6d1e2113a

2. Query automationTime fee details 
automationFeeDetails:  { executionFee: '9335556000', xcmpFee: '3316024436' }

3. Sign and send scheduleXcmpTask call ...
status.type Ready
status.type InBlock
status.type Finalized
TaskId: 177-2-3

4. Keep Listening XCM events on mangata-dev until 2023-08-05 12:00:00(1691208000) to verify that the task(taskId: 177-2-3) will be successfully executed ...
        proxy:ProxyExecuted:: (phase={"applyExtrinsic":0})
                        Result<Null, SpRuntimeDispatchError>: {"err":{"module":{"index":14,"error":"0x09000000"}}}
        proxy:ProxyExecuted:: (phase={"applyExtrinsic":0})
                        Result<Null, SpRuntimeDispatchError>: {"err":{"module":{"index":14,"error":"0x09000000"}}}
Task has been executed!
```
  • Loading branch information
imstar15 authored Aug 5, 2023
1 parent d537515 commit 3d527bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| :--- | :----: |
| Polkadot | [v0.9.38](https://github.com/paritytech/polkadot/releases/tag/v0.9.38) |
| OAK-blockchain | [v1.9.0](https://github.com/OAK-Foundation/OAK-blockchain/releases/tag/v1.9.0) |
| Mangata-node | [v0.30.0](https://github.com/mangata-finance/mangata-node/pull/501) |
| Mangata-node | [v0.30.1](https://github.com/mangata-finance/mangata-node/releases/tag/v0.30.1) |
### Steps & Logs
<details>
<summary>Dev environment</summary>
Expand All @@ -33,7 +33,7 @@

- Compile modified Mangata

https://github.com/mangata-finance/mangata-node/tree/release/v0.30.0
https://github.com/mangata-finance/mangata-node/releases/tag/v0.30.1

```
cargo build --release --features mangata-rococo,fast-runtime
Expand Down Expand Up @@ -371,7 +371,7 @@ MessageHash: 0xff304ed6aeab3e174ec667e9f69a18ebe23506836c4f53bd35aeb78503193453
| Chain | Version |
| :--- | :----: |
| Polkadot | [v0.9.38](https://github.com/paritytech/polkadot/releases/tag/v0.9.38) |
| OAK-blockchain | [v1.9.0](https://github.com/OAK-Foundation/OAK-blockchain/releases/tag/v1.9.0) |
| OAK-blockchain | [v2.0.0](https://github.com/OAK-Foundation/OAK-blockchain/releases/tag/v2.0.0) |
| Moonbeam | [runtime-2302](https://github.com/PureStake/moonbeam/releases/tag/runtime-2302) |

### Steps & Logs
Expand Down
5 changes: 4 additions & 1 deletion src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const sendExtrinsic = async (api, extrinsic, keyPair, { isSudo = false }
});

if (status.isFinalized) {
resolve(status.asFinalized.toString());
resolve({ events, blockHash: status.asFinalized.toString() });
}
}
});
Expand Down Expand Up @@ -273,3 +273,6 @@ export const calculateXcmOverallWeight = (transactCallWeight, instructionWeight,
const totalWeight = { refTime: transactCallWeight.refTime.unwrap().add(totalInstructionWeight.refTime), proofSize: transactCallWeight.proofSize.unwrap().add(totalInstructionWeight.proofSize) };
return totalWeight;
};

export const findEvent = (events, section, method) => events.find((e) => e.event.section === section && e.event.method === method);
export const getTaskIdInTaskScheduledEvent = (event) => Buffer.from(event.event.data.taskId).toString();
2 changes: 1 addition & 1 deletion src/config/mangata-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const assets = [
name: 'Turing native token',
symbol: 'TUR',
address: '',
feePerSecond: new BN('537600000000'),
feePerSecond: new BN('871400000000'),
},
];

Expand Down
18 changes: 8 additions & 10 deletions src/mangata/mangata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MangataHelper from '../common/mangataHelper';
import Account from '../common/account';
import {
askScheduleAction, ScheduleActionType,
calculateTimeout, delay, getDecimalBN, listenEvents, sendExtrinsic,
calculateTimeout, delay, getDecimalBN, listenEvents, sendExtrinsic, findEvent, getTaskIdInTaskScheduledEvent,
} from '../common/utils';
import { TuringDev, MangataDev } from '../config';

Expand Down Expand Up @@ -61,7 +61,6 @@ async function main() {
account.print();

const mangataAddress = account.getChainByName(mangataChainName)?.address;
const turingAddress = account.getChainByName(turingChainName)?.address;
const poolName = `${mangataNativeToken.symbol}-${turingNativeToken.symbol}`;

// Calculate rwards amount in pool
Expand Down Expand Up @@ -103,11 +102,9 @@ async function main() {
? { Recurring: { frequency: TASK_FREQUENCY, nextExecutionTime: executionTime } }
: { Fixed: { executionTimes: [0] } };

const providedId = `xcmp_automation_test_${(Math.random() + 1).toString(36).substring(7)}`;
const overallWeight = mangataHelper.calculateXcmTransactOverallWeight(mangataProxyCallFees.weight);
const fee = mangataHelper.weightToFee(overallWeight, 'TUR');
const xcmpCall = turingHelper.api.tx.automationTime.scheduleXcmpTask(
providedId,
schedule,
{ V3: { parents: 1, interior: { X1: { Parachain: mangataHelper.config.paraId } } } },
{ V3: { parents: 0, interior: 'Here' } },
Expand All @@ -124,17 +121,18 @@ async function main() {
const { executionFee, xcmpFee } = await turingHelper.api.rpc.automationTime.queryFeeDetails(xcmpCall);
console.log('automationFeeDetails: ', { executionFee: executionFee.toString(), xcmpFee: xcmpFee.toString() });

// Get a TaskId from Turing rpc
const taskId = await turingHelper.api.rpc.automationTime.generateTaskId(turingAddress, providedId);
console.log('TaskId:', taskId.toHuman());

// Send extrinsic
console.log('\n3. Sign and send scheduleXcmpTask call ...');
// await turingHelper.sendXcmExtrinsic(xcmpCall, account.pair, taskId);
await sendExtrinsic(turingHelper.api, xcmpCall, account.pair);
const { events } = await sendExtrinsic(turingHelper.api, xcmpCall, account.pair);

// Get taskId from TaskScheduled event
const taskScheduledEvent = findEvent(events, 'automationTime', 'TaskScheduled');
const taskId = getTaskIdInTaskScheduledEvent(taskScheduledEvent);
console.log('TaskId:', taskId);

// Listen XCM events on Mangata side
console.log(`\n4. Keep Listening XCM events on ${parachainName} until ${moment(executionTime * 1000).format('YYYY-MM-DD HH:mm:ss')}(${executionTime}) to verify that the task(taskId: ${taskId}, providerId: ${providedId}) will be successfully executed ...`);
console.log(`\n4. Keep Listening XCM events on ${parachainName} until ${moment(executionTime * 1000).format('YYYY-MM-DD HH:mm:ss')}(${executionTime}) to verify that the task(taskId: ${taskId}) will be successfully executed ...`);
await listenEvents(mangataHelper.api, 'proxy', 'ProxyExecuted');

const isTaskExecuted = await listenEvents(mangataHelper.api, 'proxy', 'ProxyExecuted', executionTime);
Expand Down

0 comments on commit 3d527bb

Please sign in to comment.