-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rewrite and publish cli * pkg * fix ci * fix task * restore cargo workflow
- Loading branch information
1 parent
554b206
commit 9d61759
Showing
32 changed files
with
6,792 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Tests | ||
name: Cargo | ||
|
||
on: | ||
workflow_dispatch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: CI | ||
on: [push] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
- run: cd cli && npm ci | ||
- run: cd cli && npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#!/usr/bin/env node | ||
|
||
import yargs from 'yargs/yargs' | ||
import { hideBin } from 'yargs/helpers' | ||
import fs from 'node:fs/promises' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
import { currentRoundIndex } from '../commands/current-round-index.js' | ||
import { listTransfers } from '../commands/list-transfers.js' | ||
import { | ||
participantCountScheduledForTransfer | ||
} from '../commands/participant-count-scheduled-for-transfer.js' | ||
import { readyForTransfer } from '../commands/ready-for-transfer.js' | ||
import { releaseRewards } from '../commands/release-rewards.js' | ||
import { rewardsScheduledFor } from '../commands/rewards-scheduled-for.js' | ||
import { roundReward } from '../commands/round-reward.js' | ||
import { scheduledForTransfer } from '../commands/scheduled-for-transfer.js' | ||
import { | ||
setMinBalanceForTransfer | ||
} from '../commands/set-min-balance-for-transfer.js' | ||
import { setNextRoundLength } from '../commands/set-next-round-length.js' | ||
import { setRoundReward } from '../commands/set-round-reward.js' | ||
import { tick } from '../commands/tick.js' | ||
|
||
const pkg = JSON.parse( | ||
await fs.readFile( | ||
fileURLToPath(new URL('../package.json', import.meta.url)), | ||
'utf8' | ||
) | ||
) | ||
|
||
yargs(hideBin(process.argv)) | ||
.env('MERIDIAN') | ||
.option('address', { | ||
alias: 'a', | ||
type: 'string', | ||
description: 'Contract address (or $MERIDIAN_ADDRESS)' | ||
}) | ||
.option('glif-token', { | ||
alias: 'g', | ||
type: 'string', | ||
description: 'GLIF token (or $MERIDIAN_GLIF_TOKEN)' | ||
}) | ||
.demandOption('address') | ||
.demandOption('glif-token') | ||
.command( | ||
'current-round-index', | ||
'Get the current round index', | ||
yargs => yargs, | ||
currentRoundIndex | ||
) | ||
.command( | ||
'list-transfers', | ||
'List transfers from last 100 blocks', | ||
yargs => yargs, | ||
listTransfers | ||
) | ||
.command( | ||
'participant-count-scheduled-for-transfer', | ||
'Watch the participant count scheduled for transfer', | ||
yargs => yargs.option('watch', { | ||
alias: 'w', | ||
type: 'boolean', | ||
default: false | ||
}), | ||
participantCountScheduledForTransfer | ||
) | ||
.command( | ||
'ready-for-transfer', | ||
'List participants ready for transfer', | ||
yargs => yargs, | ||
readyForTransfer | ||
) | ||
.command( | ||
'release-rewards', | ||
'Release rewards', | ||
yargs => yargs, | ||
releaseRewards | ||
) | ||
.command( | ||
'rewards-scheduled-for <participant>', | ||
'Get rewards scheduled for a participant', | ||
yargs => yargs.positional('participant', { type: 'string' }), | ||
rewardsScheduledFor | ||
) | ||
.command( | ||
'round-reward', | ||
'Get the current round reward', | ||
yargs => yargs, | ||
roundReward | ||
) | ||
.command( | ||
'scheduled-for-transfer', | ||
'Get all participants scheduled for transfer', | ||
yargs => yargs, | ||
scheduledForTransfer | ||
) | ||
.command( | ||
'set-min-balance-for-transfer <minBalance>', | ||
'Set the minimum balance for transfer', | ||
yargs => yargs.positional('minBalance', { type: 'string' }), | ||
setMinBalanceForTransfer | ||
) | ||
.command( | ||
'set-next-round-length <blocks>', | ||
'Set the next round length', | ||
yargs => yargs.positional('blocks', { type: 'number' }), | ||
setNextRoundLength | ||
) | ||
.command( | ||
'set-round-reward <reward>', | ||
'Set the round reward', | ||
yargs => yargs.positional('reward', { type: 'string' }), | ||
setRoundReward | ||
) | ||
.command( | ||
'tick', | ||
'Trigger a tick', | ||
yargs => yargs, | ||
tick | ||
) | ||
.demandCommand() | ||
.version(`${pkg.name}: ${pkg.version}`) | ||
.alias('v', 'version') | ||
.alias('h', 'help') | ||
.example([ | ||
['$ $0 current-round-index', 'Get the current round index'] | ||
]) | ||
.help() | ||
.parse() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createContract } from '../index.js' | ||
|
||
export const currentRoundIndex = async opts => { | ||
const { contract } = createContract(opts) | ||
console.log((await contract.currentRoundIndex()).toString()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createContract } from '../index.js' | ||
import { formatEther } from 'ethers' | ||
|
||
export const listTransfers = async opts => { | ||
const { contract } = await createContract(opts) | ||
console.error('Warning: Only showing transfers from the last 100 blocks') | ||
const events = await contract.queryFilter(contract.filters.Transfer, -100) | ||
const keys = new Set() | ||
let sum = 0n | ||
|
||
for (const event of events) { | ||
const [to, amount] = event.args | ||
const { blockNumber } = event | ||
const key = `${to}:${amount}:${blockNumber}` | ||
if (!keys.has(key)) { | ||
console.log(`- ${to}: ${formatEther(amount)}`) | ||
keys.add(key) | ||
sum += amount | ||
} | ||
} | ||
|
||
console.log(`Total: ${formatEther(sum)} / ${sum} attoFIL`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createContract } from '../index.js' | ||
import timers from 'node:timers/promises' | ||
|
||
export const participantCountScheduledForTransfer = async ({ watch, ...opts }) => { | ||
const { contract } = await createContract(opts) | ||
while (true) { | ||
const transfersLeft = await contract.participantCountScheduledForTransfer() | ||
console.log('Transfers left:', transfersLeft) | ||
if (!watch) break | ||
await timers.setTimeout(10_000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createContract } from '../index.js' | ||
import { formatEther } from 'ethers' | ||
|
||
export const readyForTransfer = async opts => { | ||
const { contract } = await createContract(opts) | ||
for (let i = 0; ; i++) { | ||
try { | ||
const address = await contract.readyForTransfer(i) | ||
const amount = await contract.rewardsScheduledFor(address) | ||
console.log(`${address} FIL ${formatEther(amount)}`) | ||
} catch (err) { | ||
break | ||
} | ||
} | ||
process.exit() | ||
} |
Oops, something went wrong.