Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 56c04a5

Browse files
authored
refactor using @filecoin-station/spark-impact-evaluator (#487)
* refactor using `@filecoin-station/spark-impact-evaluator` * bump * fix types
1 parent 3d8c8a6 commit 56c04a5

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

commands/station.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ethAddressFromDelegated, isEthAddress } from '@glif/filecoin-address'
1212
import { ethers, formatEther } from 'ethers'
1313
import { runUpdateRewardsLoop } from '../lib/rewards.js'
1414
import { runUpdateContractsLoop } from '../lib/contracts.js'
15-
import { fileURLToPath } from 'node:url'
1615

1716
const {
1817
FIL_WALLET_ADDRESS,
@@ -110,17 +109,10 @@ export const station = async ({ json, experimental }) => {
110109
'Bearer RXQ2SKH/BVuwN7wisZh3b5uXStGPj1JQIrIWD+rxF0Y='
111110
)
112111
const provider = new ethers.JsonRpcProvider(fetchRequest)
113-
const abi = JSON.parse(
114-
await fs.readFile(
115-
fileURLToPath(new URL('../lib/abi.json', import.meta.url)),
116-
'utf8'
117-
)
118-
)
119112

120113
await Promise.all([
121114
zinniaRuntime.run({
122115
provider,
123-
abi,
124116
STATION_ID,
125117
FIL_WALLET_ADDRESS: ethAddress,
126118
ethAddress,
@@ -143,7 +135,6 @@ export const station = async ({ json, experimental }) => {
143135
runMachinesLoop({ STATION_ID }),
144136
runUpdateContractsLoop({
145137
provider,
146-
abi,
147138
contracts,
148139
onActivity: (activity) => activities.submit(activity)
149140
}),

lib/contracts.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import timers from 'node:timers/promises'
22
import pRetry from 'p-retry'
33
import * as Name from 'w3name'
44
import { ethers } from 'ethers'
5+
import * as SparkImpactEvaluator from '@filecoin-station/spark-impact-evaluator'
56

67
const {
78
// https://github.com/filecoin-station/contract-addresses
@@ -10,11 +11,11 @@ const {
1011

1112
const DELAY_IN_MINUTES = 10
1213

13-
export const runUpdateContractsLoop = async ({ provider, abi, contracts, onActivity }) => {
14+
export const runUpdateContractsLoop = async ({ provider, contracts, onActivity }) => {
1415
await timers.setTimeout(2_000)
1516
while (true) {
1617
try {
17-
const newContracts = await getContractsWithRetry({ provider, abi })
18+
const newContracts = await getContractsWithRetry({ provider })
1819
contracts.splice(0)
1920
contracts.push(...newContracts)
2021
} catch (err) {
@@ -36,7 +37,7 @@ export const runUpdateContractsLoop = async ({ provider, abi, contracts, onActiv
3637
}
3738
}
3839

39-
async function getContractsWithRetry ({ provider, abi }) {
40+
async function getContractsWithRetry ({ provider }) {
4041
const contractAddresses = await pRetry(getContractAddresses, {
4142
retries: 10,
4243
onFailedAttempt: err => {
@@ -54,7 +55,7 @@ async function getContractsWithRetry ({ provider, abi }) {
5455
})
5556
console.error(`Meridian contract addresses: ${contractAddresses.join(', ')}`)
5657
return contractAddresses.map(address => {
57-
return new ethers.Contract(address, abi, provider)
58+
return new ethers.Contract(address, SparkImpactEvaluator.ABI, provider)
5859
})
5960
}
6061

lib/zinnia.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ const catchChildProcessExit = async ({
206206

207207
export async function run ({
208208
provider,
209-
abi,
210209
STATION_ID,
211210
FIL_WALLET_ADDRESS,
212211
ethAddress,
@@ -331,7 +330,6 @@ export async function run ({
331330
// size, as awaiting promises unwinds the stack
332331
return run({
333332
provider,
334-
abi,
335333
STATION_ID,
336334
FIL_WALLET_ADDRESS,
337335
ethAddress,

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"typescript": "^5.0.4"
4747
},
4848
"dependencies": {
49+
"@filecoin-station/spark-impact-evaluator": "^1.1.0",
4950
"@glif/filecoin-address": "^3.0.0",
5051
"@influxdata/influxdb-client": "^1.33.2",
5152
"@ipld/car": "^5.2.6",

0 commit comments

Comments
 (0)