Skip to content

Instantly share code, notes, and snippets.

View yornaath's full-sized avatar
🔥
buidling

Yornaath yornaath

🔥
buidling
View GitHub Profile
@yornaath
yornaath / lmsr-create-market.ts
Last active January 23, 2024 13:20
Create LMSR market
import { KeyringPair } from '@polkadot/keyring/types'
import {
batterystation,
create,
CreateMarketParams,
RpcContext,
Sdk,
swapFeeFromFloat,
ZTG,
} from '@zeitgeistpm/sdk'
@yornaath
yornaath / parimutuel-market-creation.ts
Last active January 23, 2024 14:10
Create Parimutuel market using the Zeitgeist SDK
import { KeyringPair } from '@polkadot/keyring/types'
import {
batterystation,
create,
CreateMarketParams,
RpcContext,
Sdk,
swapFeeFromFloat,
ZTG,
} from '@zeitgeistpm/sdk'
@yornaath
yornaath / randomg.ts
Created December 19, 2023 11:16
Pseudo random deterministic choice
import seedrandom from "seedrandom";
/**
* Pseudo-random number generator that returns a number between min and max deterministically based on a seed.
*
* @param seed string
* @param min min range value
* @param max max range value
* @returns number
*/
@yornaath
yornaath / bevy_navigation_constant_speed.rs
Last active August 9, 2023 12:02
Bevy: constant speed player navigation
fn player_navigation(
time: Res<Time>,
mut player_query: Query<
(
&mut KinematicCharacterController,
&mut Destination,
&mut Transform,
),
With<Player>,
>,
import { create, createStorage, CreateMarketWithPoolParams } from '@zeitgeistpm/sdk'
import { IPFS } from '@zeitgeistpm/web3.storage'
type CustomMarketMetadata = { description: string }
const storage = createStorage<CustomMarketMetadata>(
IPFS.storage({
node: { url: 'http://ipfs.zeitgeist.pm:5001', pin: false },
}),
)
import { useEffect, useState } from 'react'
import { batterystation, builder, Context, Sdk } from '@zeitgeistpm/sdk'
import { MarketList } from './components/MarketList'
const App: React.FC = () => {
const [sdk, setSdk] = useState<Partial<Sdk<Context>>>({})
useEffect(() => {
/**
* Sdk can be either RpcSdk, IndexedSdk or Both.
@yornaath
yornaath / Market.tsx
Last active September 29, 2022 19:19
import { Context, isIndexedData, isRpcData, isRpcSdk, Sdk } from '@zeitgeistpm/sdk'
import { RpcPoolPrices } from '@zeitgeistpm/sdk/dist/model/assets'
import { Pool } from '@zeitgeistpm/sdk/dist/model/swaps/pool'
import { Market } from '@zeitgeistpm/sdk/dist/model/types'
import { throws } from '@zeitgeistpm/utility/dist/error'
import { useEffect, useState } from 'react'
export const MarketComponent: React.FC<{ marketId: number; sdk: Partial<Sdk<Context>> }> = ({
sdk,
marketId,
const App: React.FC = () => {
const [sdk, setSdk] = useState<Partial<Sdk<Context>>>()
const [markets, setMarkets] = useState<Array<RpcMarket | IndexedMarket>>([])
const loadMarkets = async (sdk: Sdk<Context>) => {
const markets = await sdk.model.markets.list()
setMarkets(markets)
}
useEffect(() => {
@yornaath
yornaath / market-metadata.ts
Created September 20, 2022 11:36
Zeitgeist get market metadata
import * as ipfsClient from "ipfs-http-client";
import CID from "cids";
import { u8aToString } from "@polkadot/util";
const main = async (
metadata: string = "0x153065f773b9d3b19b9ec3ef4641bc62e714b77c086d1fa1b263331aa994789d7a8f7e21f0ceaf11ee285a2490821ca348b0"
) => {
const ipfs = await ipfsClient.create({
url: "http://ipfs.zeitgeist.pm:5001/",
});
const transfer = async (
api: ApiPromise,
receiver: string,
ammount: number
): Promise<
| Ok<BalanceTransferEvent>
| Error<RejectedFees | Canceled | DispatchError | ShouldBeUnreachable>
> => {
const transaction = api.tx.balances.transfer(receiver, ammount)