Skip to content

Commit

Permalink
better flow + docs tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Mar 19, 2024
1 parent 53f1b87 commit cd79369
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 47 deletions.
6 changes: 3 additions & 3 deletions contracts/scripts/generateTokenLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ async function main() {
contentLines = content.split('\n');
} catch {}

const host =
env.network.name === 'localhost' ? 'http://localhost:5173' : `https://${env.network.name}.stratagems.world`;
fs.writeFileSync(
`.keys/${env.network.name}-list.csv`,
contentLines
.concat(accounts.map((v) => `${v.address},https://${env.network.name}.stratagems.world#tokenClaim=${v.key}`))
.join('\n'),
contentLines.concat(accounts.map((v) => `${v.address},${host}#tokenClaim=${v.key}`)).join('\n'),
);

const addresses = accounts.map((v) => v.address);
Expand Down
75 changes: 74 additions & 1 deletion docs/contracts/GemsGenerator.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ claim the rewards earned so far using a fixed rate per point

function claimFixedRewards(address to)

| Name | Description
| ---- | -----------
| to | address to send the reward to

### **claimSharedPoolRewards**

claim the rewards earned so far in the shared pool
Expand All @@ -57,6 +61,10 @@ claim the rewards earned so far in the shared pool

function claimSharedPoolRewards(address to)

| Name | Description
| ---- | -----------
| to | address to send the reward to

### **decimals**

Returns the number of decimals the token uses.
Expand All @@ -77,6 +85,10 @@ The amount of reward an account has accrued so far. Does not include already wit

function earnedFromFixedRate(address account) view returns (uint256)

| Name | Description
| ---- | -----------
| account | address to query about

### **earnedFromFixedRateMultipleAccounts**

The amount of reward an account has accrued so far. Does not include already withdrawn rewards.
Expand All @@ -87,6 +99,10 @@ The amount of reward an account has accrued so far. Does not include already wit

function earnedFromFixedRateMultipleAccounts(address[] accounts) view returns (uint256[] result)

| Name | Description
| ---- | -----------
| accounts | list of address to query about

### **earnedFromPoolRate**

The amount of reward an account has accrued so far. Does not include already withdrawn rewards.
Expand All @@ -97,6 +113,10 @@ The amount of reward an account has accrued so far. Does not include already wit

function earnedFromPoolRate(address account) view returns (uint256)

| Name | Description
| ---- | -----------
| account | address to query about

### **earnedFromPoolRateMultipleAccounts**

The amount of reward an account has accrued so far. Does not include already withdrawn rewards.
Expand All @@ -107,6 +127,39 @@ The amount of reward an account has accrued so far. Does not include already wit

function earnedFromPoolRateMultipleAccounts(address[] accounts) view returns (uint256[] result)

| Name | Description
| ---- | -----------
| accounts | list of address to query about

### **enableGame**

Allow a contract (a game) to add points to the rewards system

*sig hash*: `0x16cf09f8`

*Signature*: enableGame(address,uint256)

function enableGame(address game, uint256 weight)

| Name | Description
| ---- | -----------
| game | the contract that is allowed to call in
| weight | (not implemented, act as boolean for now) (0 disable the game)

### **games**

return the weight of the game

*sig hash*: `0x79131a19`

*Signature*: games(address)

function games(address game) view returns (uint256 weight)

| Name | Description
| ---- | -----------
| game | the contract to query about

### **getTotalRewardPerPointWithPrecision24**

The amount of reward each point has earned so far
Expand All @@ -117,6 +170,16 @@ The amount of reward each point has earned so far

function getTotalRewardPerPointWithPrecision24() view returns (uint256)

### **global**

return the current global state

*sig hash*: `0xa05f9906`

*Signature*: global()

function global() view returns ((uint40 lastUpdateTime, uint104 totalRewardPerPointAtLastUpdate, uint112 totalPoints))

### **name**

Returns the name of the token.
Expand All @@ -135,7 +198,7 @@ Returns the symbol of the token.

*Signature*: symbol()

function symbol() view returns (string)
function symbol() pure returns (string)

### **totalSupply**

Expand Down Expand Up @@ -167,6 +230,16 @@ Transfers `amount` tokens from address `from` to address `to`.

function transferFrom(address, address, uint256) pure returns (bool)

### **update**

update the global pool rate

*sig hash*: `0xa2e62045`

*Signature*: update()

function update()


## Events

Expand Down
1 change: 1 addition & 0 deletions docs/contracts/Stratagems.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ event CommitmentRevealed(address indexed player, uint24 indexed epoch, bytes24 i
| commitmentHash | the hash of the moves
| moves | the moves
| furtherMoves | hash of further moves, unless bytes32(0) which indicate end.
| newReserveAmount | new amount in reserve as a result

### **CommitmentVoid**

Expand Down
8 changes: 6 additions & 2 deletions docs/guide/extending-the-world/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ Each Land have the following attributes:
- `int8 delta`: whether the land is gaining life or losing life due to its neighboroud
- `address owner`: the owner of land, the player who deposited a stake to choose a faction

The `producingEpochs` is particularly useful to track whether a Land has been growing since your extension kept track
The `producingEpochs` is particularly useful to track whether a Land has been growing since you can use to track it even if your game transaction happen later.

This can be used for example to make a game where Land produce units as long as growth of the land is positive.

This can lead to very interesting social interaction between players of the base game and the one playing the extension game.
This can lead to very interesting social interaction between players of the base game and the one playing the extended game.

You can of course also creating incentives mechanism to attract player of the base game.

Stratagems has its own token: Gems, which does not have any role in the base game but is given to player whose land is propsering. Gems is thus a great token to integrate.
40 changes: 40 additions & 0 deletions web/src/lib/actions/commit/TransactionComponent.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script lang="ts">
import type {Writable} from 'svelte/store';
import type {CommitState} from '.';
import {JsonView} from '@zerodevx/svelte-json-view';
import {serializeJSONWithBigInt} from '$utils/js';
import {formatEther} from 'viem';
export let state: Writable<CommitState>;
$: value = $state.fuzdData?.value;
$: formatedValue = value ? formatEther(value) : undefined;
</script>

<div class="form">
<p>
This Transaction will Commit Your Moves. You can cancel (or Replace it with new Moves) before the Resolution Phase
Start.
</p>

{#if formatedValue}
<p>
The transaction is also sending {formatedValue} ETH so we can reveal on your behalf. This is a worst-case estimate
and unspend value can be used for further tx.
</p>
{/if}

{#if $state.fuzdData}
<p>
Note that we will do our best to reveal your move, but cannot guarantee it. You can always reveal yourself when
the reveal phase start.
</p>
{/if}
<!-- <JsonView json={serializeJSONWithBigInt($state)} depth={1} /> -->
</div>

<style>
p {
margin-bottom: 1rem;
}
</style>
5 changes: 3 additions & 2 deletions web/src/lib/actions/commit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {time} from '$lib/blockchain/time';
import {timeToText} from '$utils/time';
import {localMoveToContractMove, type CommitMetadata} from '$lib/account/account-data';
import PermitComponent from './PermitComponent.svelte';
import {getRoughGasPriceEstimate} from '$utils/ethereum/gas';
import TransactionComponent from './TransactionComponent.svelte';
import {gameConfig} from '$lib/blockchain/networks';

export type CommitState = {
Expand Down Expand Up @@ -262,7 +262,7 @@ export async function startCommit() {
title: 'Perform the Commit Transaction',
action: 'OK',
description: `This Transaction will Commit Your Moves. You can cancel (or Replace it with new Moves) before the Resolution Phase Start.`,
// component: PermitComponent,
component: TransactionComponent,
execute: async (state: CommitState) => {
const {amountToAdd, permit, fuzdData, gasPrice, epochNumber} = state;

Expand Down Expand Up @@ -464,6 +464,7 @@ export async function startCommit() {
type: 'commit',
currentStepIndex: writable(0),
state: writable({amountToAllow: undefined, amountToAdd: undefined}),
completionMessage: 'Commitment Complete.',
steps,
};
currentFlow.start(flow);
Expand Down
61 changes: 41 additions & 20 deletions web/src/lib/actions/flow/Flow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,54 @@

{#if $currentFlow && $currentStepIndex !== undefined && $state}
<Modal oncancel={() => cancel()}>
{#if currentStep}
<div class="title">
{currentStep.title}
</div>
{#if currentStep.component}
<svelte:component this={currentStep.component} {state} />
<div class="wrapper-top">
{#if currentStep}
<div class="title">
{currentStep.title}
</div>
{#if currentStep.component}
<svelte:component this={currentStep.component} {state} />
{:else}
<p class="description">{currentStep.description}</p>
{/if}
{:else}
<p class="description">{currentStep.description}</p>
<p>{$currentFlow.completionMessage ? $currentFlow.completionMessage : 'Steps Completed'}</p>
{/if}
{/if}
</div>

{#if !currentStep || currentStep.action}
<div class="actions">
{#if currentStep}
<button on:click={() => cancel()}>Back</button>
{:else}
<p>Steps completed</p>
{/if}
<button class="primary" on:click={() => execute()}>{action}</button>
</div>
{:else}
<p>Please wait...</p>
{/if}
<div class="wrapper-bottom">
{#if !currentStep || currentStep.action}
<div class="actions">
{#if currentStep}
<button on:click={() => cancel()}>Back</button>
{/if}
<button class="primary" on:click={() => execute()}>{action}</button>
</div>
{:else}
<p>Please wait...</p>
{/if}
</div>
</Modal>
{/if}

<style>
.wrapper-top {
height: calc(100% - 48px);
display: flex;
flex-direction: column;
justify-content: start;
width: 100%;
overflow: auto;
}
.wrapper-bottom {
display: flex;
flex-direction: column;
justify-content: end;
height: 48px;
width: 100%;
}
.title {
font-weight: bold;
font-size: clamp(1rem, 4vw, 1.25rem);
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/actions/flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Flow<State> = {
steps: Step<State>[];
state: Writable<State>;
currentStepIndex: Writable<number>;
completionMessage?: string;
};

export type FlowState = Flow<any> | undefined;
Expand Down
23 changes: 4 additions & 19 deletions web/src/lib/ui/indexer/IndexerView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import {indexerView} from './indexerView';
import ModalContainer from '$utils/ui/modals/ModalContainer.svelte';
import {fly} from 'svelte/transition';
// import JSONTree from 'svelte-json-tree';
import {serializeJSONWithBigInt} from '$utils/js';
function addLengthToFields(v: any): any {
const keys = Object.keys(v);
const n = {};
Expand All @@ -18,24 +19,8 @@
}
return n;
}
function transform(json: any): any {
if (typeof json === 'bigint') {
return json.toString();
} else if (typeof json === 'object') {
if (Array.isArray(json)) {
return json.map(transform);
} else {
const keys = Object.keys(json);
const n = {} as any;
for (const key of keys) {
n[key] = transform(json[key]);
}
return n;
}
}
return json;
}
$: stateDisplayed = $state && transform(addLengthToFields($state));
$: stateDisplayed = $state && serializeJSONWithBigInt(addLengthToFields($state));
</script>

{#if $indexerView.open}
Expand Down
18 changes: 18 additions & 0 deletions web/src/utils/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@
export function copy<T>(obj: T): T {
return JSON.parse(JSON.stringify(obj));
}

export function serializeJSONWithBigInt(json: any): any {
if (typeof json === 'bigint') {
return json.toString();
} else if (typeof json === 'object') {
if (Array.isArray(json)) {
return json.map(serializeJSONWithBigInt);
} else {
const keys = Object.keys(json);
const n = {} as any;
for (const key of keys) {
n[key] = serializeJSONWithBigInt(json[key]);
}
return n;
}
}
return json;
}

0 comments on commit cd79369

Please sign in to comment.