Skip to content

Commit

Permalink
feat: add farming script & more assets gov calls (#1906)
Browse files Browse the repository at this point in the history
Signed-off-by: GopherJ <[email protected]>

Signed-off-by: GopherJ <[email protected]>
  • Loading branch information
GopherJ authored Nov 30, 2022
1 parent 9633dcd commit 25b24d0
Show file tree
Hide file tree
Showing 13 changed files with 921 additions and 1,427 deletions.
3 changes: 3 additions & 0 deletions runtime/heiko/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ impl Contains<RuntimeCall> for WhiteListFilter {
RuntimeCall::Assets(pallet_assets::Call::force_create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_set_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_asset_status { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_clear_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_cancel_approval { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_transfer { .. }) |
// Governance
// Call::Sudo(_) |
RuntimeCall::Democracy(_) |
Expand Down
3 changes: 3 additions & 0 deletions runtime/kerria/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ impl Contains<RuntimeCall> for WhiteListFilter {
RuntimeCall::Assets(pallet_assets::Call::force_create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_set_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_asset_status { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_clear_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_cancel_approval { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_transfer { .. }) |
// Governance
RuntimeCall::Sudo(_) |
RuntimeCall::Democracy(_) |
Expand Down
3 changes: 3 additions & 0 deletions runtime/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ impl Contains<RuntimeCall> for WhiteListFilter {
RuntimeCall::Assets(pallet_assets::Call::force_create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_set_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_asset_status { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_clear_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_cancel_approval { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_transfer { .. }) |
// Governance
// RuntimeCall::Sudo(_) |
RuntimeCall::Democracy(_) |
Expand Down
3 changes: 3 additions & 0 deletions runtime/vanilla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ impl Contains<RuntimeCall> for WhiteListFilter {
RuntimeCall::Assets(pallet_assets::Call::force_create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_set_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_asset_status { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_clear_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_cancel_approval { .. }) |
RuntimeCall::Assets(pallet_assets::Call::force_transfer { .. }) |
// Governance
RuntimeCall::Sudo(_) |
RuntimeCall::Democracy(_) |
Expand Down
785 changes: 0 additions & 785 deletions scripts/helper/.yarn/releases/yarn-3.2.0.cjs

This file was deleted.

807 changes: 807 additions & 0 deletions scripts/helper/.yarn/releases/yarn-3.3.0.cjs

Large diffs are not rendered by default.

631 changes: 0 additions & 631 deletions scripts/helper/.yarn/releases/yarn-rc.js

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/helper/.yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-outdated.cjs
spec: "https://mskelton.dev/yarn-outdated/v2"

yarnPath: .yarn/releases/yarn-rc.js
yarnPath: .yarn/releases/yarn-3.3.0.cjs
3 changes: 2 additions & 1 deletion scripts/helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"bignumber.js": "^9.0.2",
"dotenv": "^16.0.0",
"shelljs": "^0.8.5"
}
},
"packageManager": "[email protected]"
}
4 changes: 2 additions & 2 deletions scripts/helper/src/commands/set/add-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { readFile } from '../../utils'
import BigNumber from 'bignumber.js'

export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('set market reward speed')
return createCommand('add market')
.argument('<input>', 'path to reward csv', {
validator: program.STRING
})
Expand All @@ -28,7 +28,7 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
)

const markets = (await readFile(input.toString(), 'utf8'))
.split(/\r\n/)
.split(/\r?\n/)
.slice(1)
.map(row => row.split(',').filter(Boolean))
.filter(cols => cols.length >= 4)
Expand Down
90 changes: 90 additions & 0 deletions scripts/helper/src/commands/set/farming-reward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { getApi, getCouncilThreshold, nextNonce } from '../../utils'
import { Command, CreateCommandParameters, program } from '@caporal/core'
import { Keyring } from '@polkadot/api'
import { readFile } from '../../utils'
import BigNumber from 'bignumber.js'

export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('set farming reward speed')
.argument('<input>', 'path to reward csv', {
validator: program.STRING
})
.option('-p, --para-ws [url]', 'the parachain API endpoint', {
default: 'wss://rpc.parallel.fi'
})
.option('-d, --dry-run [boolean]', 'whether to execute using PARA_CHAIN_SUDO_KEY', {
validator: program.BOOLEAN,
default: true
})
.action(async actionParameters => {
const {
logger,
args: { input },
options: { paraWs, dryRun }
} = actionParameters
const api = await getApi(paraWs.toString())
const signer = new Keyring({ type: 'sr25519' }).addFromUri(
`${process.env.PARA_CHAIN_SUDO_KEY || '//Dave'}`
)
const isParallel = (await api.rpc.system.chain()).toString() === 'Parallel'
const payer = isParallel
? 'p8B3QXweBQKzu8DhkggwJqFkUVQ53kB1RejtFQ8q3JMSFqqMd'
: 'hJFHzsKENPsaqPJT2k6D4VYUKz2eFxxW7AVfG9zvL3Q1R7sFp'
const rewardAsset = isParallel ? '1' : '0'
const lockDuration = '0'
const blockNumber = (await api.rpc.chain.getHeader()).number.toBn()

const rewards = (await readFile(input.toString(), 'utf8'))
.split(/\r?\n/)
.slice(1)
.map(row => row.split(',').filter(Boolean))
.filter(cols => cols.length >= 4)
.map(([assetId, assetName, amount, rewardDuration]) => [
assetId,
assetName,
new BigNumber(amount).multipliedBy('1000000000000').toString(),
new BigNumber(rewardDuration).toString()
])

const proposal = api.tx.utility.batchAll(
await Promise.all(
rewards.map(async ([assetId, assetName, amount, rewardDuration]) => {
logger.info(
` assetId: ${assetId}, assetName: ${assetName}, amount: ${amount}, rewardDuration: ${rewardDuration} `
)
// eslint-disable-next-line
const pool = (await api.query.farming.pools(assetId, rewardAsset, null)) as any
if (pool && pool.unwrapOrDefault().periodFinish.toBn().gt(blockNumber)) {
amount = '0'
}
return api.tx.farming.dispatchReward(
assetId,
rewardAsset,
lockDuration,
{ Id: payer },
amount,
rewardDuration
)
})
)
)

const tx = api.tx.generalCouncil.propose(
await getCouncilThreshold(api),
proposal,
proposal.length
)

if (dryRun) {
return logger.info(`hex-encoded call: ${tx.toHex()}`)
}

await tx
.signAndSend(signer, { nonce: await nextNonce(api, signer) })
.then(() => process.exit(0))
.catch(err => {
logger.error(err.message)
process.exit(1)
})
})
}
2 changes: 1 addition & 1 deletion scripts/helper/src/commands/set/market-reward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
)

const rewards = (await readFile(input.toString(), 'utf8'))
.split(/\r\n/)
.split(/\r?\n/)
.slice(1)
.map(row => row.split(',').filter(Boolean))
.filter(cols => cols.length >= 4)
Expand Down
12 changes: 6 additions & 6 deletions scripts/helper/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Manual changes might be lost - proceed with caution!

__metadata:
version: 4
version: 6
cacheKey: 8

"@babel/runtime@npm:^7.17.9":
Expand Down Expand Up @@ -1591,7 +1591,7 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:8.10.0, eslint@npm:^8.10.0":
"eslint@npm:^8.10.0":
version: 8.10.0
resolution: "eslint@npm:8.10.0"
dependencies:
Expand Down Expand Up @@ -2908,14 +2908,14 @@ resolve@^1.1.6:

"resolve@patch:resolve@^1.1.6#~builtin<compat/resolve>":
version: 1.22.0
resolution: "resolve@patch:resolve@npm%3A1.22.0#~builtin<compat/resolve>::version=1.22.0&hash=00b1ff"
resolution: "resolve@patch:resolve@npm%3A1.22.0#~builtin<compat/resolve>::version=1.22.0&hash=c3c19d"
dependencies:
is-core-module: ^2.8.1
path-parse: ^1.0.7
supports-preserve-symlinks-flag: ^1.0.0
bin:
resolve: bin/resolve
checksum: b63b73ecbb7928e71c30e231f6adc380fca66bd5819a1b1324d3dcae573c726d9923df06eef3ac50be52b1dcea67272f3b6f12ba2e87ec8a9d3ebdf8454103bb
checksum: c79ecaea36c872ee4a79e3db0d3d4160b593f2ca16e031d8283735acd01715a203607e9ded3f91f68899c2937fa0d49390cddbe0fb2852629212f3cda283f4a7
languageName: node
linkType: hard

Expand Down Expand Up @@ -3438,11 +3438,11 @@ resolve@^1.1.6:

"typescript@patch:typescript@~4.5.5#~builtin<compat/typescript>":
version: 4.5.5
resolution: "typescript@patch:typescript@npm%3A4.5.5#~builtin<compat/typescript>::version=4.5.5&hash=32657b"
resolution: "typescript@patch:typescript@npm%3A4.5.5#~builtin<compat/typescript>::version=4.5.5&hash=bcec9a"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: ed34e0986bc395da29a9a749fc980741fcbf698c205d6dc282310a652ee4ae61b571c26fd62c8a264ec26ff23ef12d888d5db7b41031cfaad1798db0d090f5c3
checksum: 858c61fa63f7274ca4aaaffeced854d550bf416cff6e558c4884041b3311fb662f476f167cf5c9f8680c607239797e26a2ee0bcc6467fbc05bfcb218e1c6c671
languageName: node
linkType: hard

Expand Down

0 comments on commit 25b24d0

Please sign in to comment.