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

Automation time #41

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Filip Kalebo <filip@rustsyndi.cat>"
],
"private": true,
"version": "0.3.0",
"version": "0.3.2",
"license": "Bagpipes License",
"type": "module",
"scripts": {
Expand All @@ -33,7 +33,6 @@
"@galacticcouncil/sdk": "^3.0.0",
"@metamask/providers": "^11.1.1",
"@metamask/types": "^1.1.0",
"@polkadot-api/descriptors": "file:.papi/descriptors",
"@polkadot/api": "^12.2.1",
"@polkadot/api-augment": "^12.2.1",
"@polkadot/api-base": "^12.2.1",
Expand All @@ -57,7 +56,6 @@
"@polkadot/ui-keyring": "^3.1.4",
"@polkadot/util": "^13.0.2",
"@polkadot/util-crypto": "^13.0.2",
"@polkadot/wasm-crypto": "^7.3.2",
"@sub-wallet/wallet-connect": "./src/components/Wallet/connect-wallet",
"@subwallet/wallet-connect": "^0.2.3",
"@testing-library/jest-dom": "^5.14.1",
Expand Down Expand Up @@ -107,7 +105,6 @@
},
"devDependencies": {
"@metamask/detect-provider": "^2.0.0",
"@polkadot/dev": "^0.66.28",
"@types/js-yaml": "^4.0.9",
"@types/pako": "^2.0.3",
"@types/react": "^18.2.15",
Expand Down
1,312 changes: 1,312 additions & 0 deletions public/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 15 additions & 25 deletions src/Chains/ChainsInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ export function listChains() {
};
chainList[2034] = HydraDX;

const Turing: ChainInfo = {
name: 'turing',
display: 'Turing (Kusama)',
paraid: 2114,
prefix: 51,
token_decimals: 10,
symbol: 'TUR',
logo: '/chains/turing.png',
relayParent: 'kusama',
parachain: true
};
chainList[2114] = Turing;

const Ethereum: ChainInfo = {
name: 'ethereum',
display: 'Ethereum',
Expand Down Expand Up @@ -168,19 +181,7 @@ export function listChains() {
};
chainList[2032] = Interlay;

const Kabocha: ChainInfo = {
name: 'kabocha',
display: 'Kabocha',
paraid: 2113,
prefix: 27,
token_decimals: 12,
logo: '/chains/kabocha.svg',
parachain: true,
relay: false,
relayParent: 'kusama',
symbol: 'KAB'
};
chainList[2113] = Kabocha;




Expand Down Expand Up @@ -253,18 +254,7 @@ export function listChains() {
};
chainList[10000] = Rococo;

const Sora: ChainInfo = {
name: 'sora',
display: 'Sora (Rococo)',
paraid: 2011, // change me
prefix: 0, //change me
token_decimals: 10,
logo: '/chains/sora.svg',
relayParent: 'rococo',
parachain: true,
symbol: 'SORA'
};
chainList[2011] = Sora;

// only rococo > rococo assethub transfers is supported
const RococoAssethub: ChainInfo = {
name: 'rococo_assethub',
Expand Down
2 changes: 2 additions & 0 deletions src/Chains/DraftTx/DraftSwapTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export async function getHydradxAssetSymbolDecimals(
};
return assetInfo;
}


// Swap functionality | THIS SUPPORTS ALL SWAPS ON HYDRA NOT ONLY OMNIPOOL SELL!! // FLIPCHAN
/// put in a sell order to sell/swap asset A for asset B on omnipool
/// Input:
Expand Down
30 changes: 30 additions & 0 deletions src/Chains/DraftTx/DraftxTransferTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,36 @@ export async function assethub2ethereum(eth_account: string, amount: any) {
return tx;
}



// input: 2024-10-15T12:00:00Z
// outpout: 1728993600
function human2unixtime(inputen: string) {
const date = new Date(inputen);
return Math.floor(date.getTime() / 1000);
}

// schedule a call on turing
export async function schedule_task(transfer_tx: any, datestring: string){
const future_timestamp = human2unixtime(datestring); //"2024-10-15T19:00:00Z"
//const transfer_tx = await turing2moonriver(accountido, amount);
const api = await getApiInstance("turing");
console.log(`unix timestamp: `, future_timestamp);
const tx_me = await api.tx.automationTime.scheduleDynamicDispatchTask(
{ fixed: {executionTimes: [future_timestamp,]}},
transfer_tx
);
return tx_me;
}









// Paseo relay chain

// works with this input
Expand Down
13 changes: 9 additions & 4 deletions src/Chains/api/light-client/SmoldotWorker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

/*
// `dot` is the name we gave to `npx papi add`
import { dot } from "@polkadot-api/descriptors"
import { createClient } from "polkadot-api"
Expand All @@ -6,14 +8,14 @@ import { chainSpec } from "polkadot-api/chains/polkadot";
import { startFromWorker } from "polkadot-api/smoldot/from-worker";

// Using vite
import SmWorker from "polkadot-api/smoldot/worker";
const worker = new SmWorker();
//import SmWorker from "polkadot-api/smoldot/worker";
//const worker = new SmWorker();

// Using Webpack
// const worker = new Worker(
// new URL("polkadot-api/smoldot/worker", import.meta.url)
// );

const smoldot = startFromWorker(worker);
const chain = await smoldot.addChain({ chainSpec });

Expand All @@ -35,4 +37,7 @@ const dotApi = client.getTypedApi(dot)
// get the value for an account
const accountInfo = await dotApi.query.System.Account.getValue(
"16JGzEsi8gcySKjpmxHVrkLTHdFHodRepEz8n244gNZpr9J",
)
)
.

*/
3 changes: 2 additions & 1 deletion src/Chains/api/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export const CHAIN_METADATA = {
turing: {
chain: "turing",
endpoints: [
"wss://rpc.turing.oak.tech"
"wss://turing-rpc.dwellir.com",
// "wss://rpc.turing.oak.tech"
],
queryAssetPaths: ["assetRegistry.metadata"],
queryBalancePaths: ["system.account" ,"tokens.accounts"],
Expand Down
2 changes: 1 addition & 1 deletion src/components/Bagpipes/BagpipesFlow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ const BagpipesFlow = () => {
console.log(`got form data`);
console.log(`isActionDataComplete actionType:`, node.formData.action);

if (["Remark", "vote", "stake", "delegate", "ink"].includes(node.formData.action)) {
if (["Remark", "vote", "stake", "delegate", "ink", "ScheduleTransfer"].includes(node.formData.action)) {

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export interface SwapAction {
target: ActionData;
}

export interface ScheduleTransferAction {
actionType: 'ScheduleTransfer';
source: ActionData;
target: ActionData;
}


export interface xTransferAction {
actionType: 'xTransfer';
source: ActionData;
Expand All @@ -88,5 +95,5 @@ export interface TransferAction {
}


export type ActionType = SwapAction | InkAction | DelegateAction | StakeAction | VoteAction | xTransferAction | RemarkAction | TransferAction;
export type ActionType = SwapAction | ScheduleTransferAction | InkAction | DelegateAction | StakeAction | VoteAction | xTransferAction | RemarkAction | TransferAction;

43 changes: 42 additions & 1 deletion src/components/Bagpipes/CustomNodes/ActionNode/ActionNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { query_contract } from '../../../../Chains/DraftTx/DraftInk';
import SwapSVG from '/swap.svg';
import xTransferSVG from '/xTransfer.svg';
import RemarkSVG from '/remark.svg';
import ScheduleTransferSVG from '/clock.svg';
import VoteSVG from '/vote.svg';
import DelegateSVG from '/delegate.svg';
import InkSVG from '/ink.svg';
Expand Down Expand Up @@ -87,6 +88,7 @@ export default function ActionNode({ children, data, isConnectable }) {
const getActionImage = () => {
if (formState.action === 'swap') return SwapSVG;
if (formState.action === 'xTransfer') return xTransferSVG;
if (formState.action === 'ScheduleTransfer') return ScheduleTransferSVG;
if (formState.action === "remark") return RemarkSVG;
if (formState.action === "Remark") return RemarkSVG;
if (formState.action === "stake") return StakeSVG;
Expand Down Expand Up @@ -282,6 +284,14 @@ function get_previous_node() {
return previousNodeFormData;
}

function get_next_node() {
const nodes = scenarios[activeScenarioId]?.diagramData?.nodes || [];
const currentNodeIndex = nodes.findIndex(node => node.id === nodeId);
const previousNode = currentNodeIndex > 0 ? nodes[currentNodeIndex + 1] : null;
const previousNodeFormData = previousNode ? previousNode.formData : null;
return previousNodeFormData;
}


// store the system remark message
const setRemark = (value) => {
Expand All @@ -308,6 +318,27 @@ function get_previous_node() {

};


const setDateSchedule = (value) => {
const currentNodeFormData = scenarios[activeScenarioId]?.diagramData?.nodes?.find(node => node.id === nodeId)?.formData;
console.log(`currentNodeFormData: `, currentNodeFormData);
const currentActionData = currentNodeFormData.actionData || {};

currentActionData.actionType = 'ScheduleTransfer';
const updatedActionData = {
...currentActionData,
source: get_previous_node(),
target: get_next_node(),
extra: value.target.value

};
setActionData(updatedActionData);
saveActionDataForNode(activeScenarioId, nodeId, updatedActionData);
console.log(`ScheduleTransfer wrote updated data: `, updatedActionData);

};


const setDelegateConviction = (value) => {
const currentNodeFormData = scenarios[activeScenarioId]?.diagramData?.nodes?.find(node => node.id === nodeId)?.formData;
var inputen = value.target.value;
Expand Down Expand Up @@ -565,7 +596,7 @@ console.log('previousNodeFormData: ', previousNodeFormData);
action: value
}));


console.log(`[handleDropdownClick] formState:`, formState);
// Create action data based on the selected value
const newActionData = convertFormStateToActionType(
{ ...formState, action: value },
Expand Down Expand Up @@ -641,6 +672,7 @@ console.log('previousNodeFormData: ', previousNodeFormData);
SwapSVG={SwapSVG}
xTransferSVG={xTransferSVG}
RemarkSVG={RemarkSVG}
ScheduleTransferSVG={ScheduleTransferSVG}
VoteSVG={VoteSVG}
DelegateSVG={DelegateSVG}
InkSVG={InkSVG}
Expand Down Expand Up @@ -688,6 +720,15 @@ console.log('previousNodeFormData: ', previousNodeFormData);
</div>
)}


{formState && formState.action === 'ScheduleTransfer' && (

<div className="in-node-border rounded m-2 p-2 ">Schedule a XCM asset tranfer on date:
<input required min={new Date().toISOString().split('T')[0]} onChange={(newValue) => setDateSchedule(newValue)} type="date" id="contact-name" placeholder="Message" className="w-full px-3 py-2 text-sm leading-tight text-gray-700 border rounded shadow appearance-none focus:outline-none focus:shadow-outline" />
</div>
)}


{formState && formState.action === 'ink' && (

<div className="in-node-border rounded m-2 p-2 ">Contract address:
Expand Down
20 changes: 19 additions & 1 deletion src/components/Bagpipes/CustomNodes/ActionNode/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type SelectorProps = {
setDropdownVisible: (visible: boolean) => void;
SwapSVG: string;
xTransferSVG: string;
ScheduleTransferSVG: string;
RemarkSVG: string;
iIcon: string;
VoteSVG: string;
Expand Down Expand Up @@ -57,7 +58,7 @@ export function useOutsideAlerter(ref: React.RefObject<HTMLElement>, callback: (
}


const Selector = React.forwardRef<HTMLDivElement, SelectorProps>(({ handleDropdownClick, SwapSVG, xTransferSVG, VoteSVG, RemarkSVG, DelegateSVG, InkSVG, StakeSVG }, ref) => {
const Selector = React.forwardRef<HTMLDivElement, SelectorProps>(({ handleDropdownClick, SwapSVG, xTransferSVG, VoteSVG, RemarkSVG, DelegateSVG, ScheduleTransferSVG, InkSVG, StakeSVG }, ref) => {
const { theme } = React.useContext(ThemeContext);


Expand Down Expand Up @@ -107,6 +108,23 @@ const Selector = React.forwardRef<HTMLDivElement, SelectorProps>(({ handleDropdo

</div>



<div onClick={() => handleDropdownClick('ScheduleTransfer')} className="hovering flex items-center p-2 hover:bg-gray-200 relative">
<div className='bg-white flex justify-center align-center p-1 mr-2 border rounded h-6'>

<img src={ScheduleTransferSVG} alt="Vite" className="w-3 h-4border rounded" />
</div>
<div className='text-xs font-semibold mr-2'>ScheduleTransfer</div>
<Tippy theme="light" content="Delegate voting power on all tracks in Polkadot's opengov">
<span className='absolute top-0 right-0 mt-1 mr-1 bg-blue-100 hover:bg-blue-200 p-1 rounded-full shadow-md cursor-pointer flex items-center justify-center w-3 h-3'>
<img src={icons.iIcon} className='w-1 h-1' alt="Info"/>
</span>
</Tippy>

</div>


<div onClick={() => handleDropdownClick('delegate')} className="hovering flex items-center p-2 hover:bg-gray-200 relative">
<div className='bg-white flex justify-center align-center p-1 mr-2 border rounded h-6'>

Expand Down
6 changes: 6 additions & 0 deletions src/components/Bagpipes/CustomNodes/ActionNode/actionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export function convertFormStateToActionType(formState: any, assetIn: any, asset
source: actionDataIn,
target: actionDataOut
};
case 'ScheduleTransfer':
return {
actionType: 'ScheduleTransfer',
source: actionDataIn,
target: actionDataOut,
};
case 'ink':
return {
actionType: 'ink',
Expand Down
5 changes: 5 additions & 0 deletions src/components/Bagpipes/CustomNodes/ActionNode/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const actions = [
logo: '',
information: 'Transfer allows you to move assets within a single chain.'
},
{
name: 'ScheduleTransfer',
logo: '/clock.svg',
information: 'Schedule a transfer with Turing'
},
{
name: 'delegate',
logo: '/delegate.svg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function processAction(action: ActionType) {
case 'xTransfer':
// Here, TypeScript knows that "action" has the shape of "xTransferAction"
break;
case 'ScheduleTransfer':
break;
case 'remark':
break;
case 'ink':
Expand Down
Loading
Loading