Skip to content

Commit

Permalink
Add relays to dev env, bump image version in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kanshi committed Oct 17, 2023
1 parent 24b6390 commit 821cc38
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 18 deletions.
2 changes: 1 addition & 1 deletion operations/deploy-distribution-dev.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "deploy-distribution-dev" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.2"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npm"]
command = "run"
args = ["deploy"]
Expand Down
2 changes: 1 addition & 1 deletion operations/deploy-distribution-live.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "deploy-distribution-live" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.2"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npm"]
command = "run"
args = ["deploy"]
Expand Down
2 changes: 1 addition & 1 deletion operations/deploy-distribution-stage.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "deploy-distribution-stage" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.2"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npm"]
command = "run"
args = ["deploy"]
Expand Down
2 changes: 1 addition & 1 deletion operations/deploy-relay-registry-dev.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "deploy-relay-registry-dev" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.2"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npm"]
command = "run"
args = ["deploy"]
Expand Down
2 changes: 1 addition & 1 deletion operations/deploy-relay-registry-live.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "deploy-relay-registry-live" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.2"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npm"]
command = "run"
args = ["deploy"]
Expand Down
2 changes: 1 addition & 1 deletion operations/deploy-relay-registry-stage.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "deploy-relay-registry-stage" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.2"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npm"]
command = "run"
args = ["deploy"]
Expand Down
53 changes: 53 additions & 0 deletions operations/dev-tests/add-relays-dev.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
job "add-relays-dev" {
datacenters = ["ator-fin"]
type = "batch"

reschedule {
attempts = 0
}

task "add-relays-dev-task" {
driver = "docker"

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npx"]
command = "ts-node"
args = ["scripts/relay-registry/add-relays.ts"]
}

vault {
policies = ["relay-registry-dev"]
}

template {
data = <<EOH
{{with secret "kv/relay-registry/dev"}}
RELAY_REGISTRY_OWNER_KEY="{{.Data.data.RELAY_REGISTRY_OWNER_KEY}}"
CONSUL_TOKEN="{{.Data.data.CONSUL_TOKEN}}"
{{end}}
EOH
destination = "secrets/file.env"
env = true
}

env {
PHASE="dev"
CONSUL_IP="127.0.0.1"
CONSUL_PORT="8500"
TEST_ACCOUNTS_KEY="facilitator/goerli/dev/test-accounts"
RELAY_REGISTRY_ADDRESS_CONSUL_KEY="smart-contracts/dev/relay-registry-address"
}

restart {
attempts = 0
mode = "fail"
}

resources {
cpu = 4096
memory = 4096
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

job "add-scores-live" {
job "add-scores-dev" {
datacenters = ["ator-fin"]
type = "batch"

reschedule {
attempts = 0
}

task "add-scores-live-task" {
task "add-scores-dev-task" {
driver = "docker"

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.19"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npx"]
command = "ts-node"
args = ["scripts/distribution/add-scores.ts"]
Expand All @@ -22,12 +22,12 @@ job "add-scores-live" {
}

vault {
policies = ["distribution-live"]
policies = ["distribution-dev"]
}

template {
data = <<EOH
{{with secret "kv/distribution/live"}}
{{with secret "kv/distribution/dev"}}
DISTRIBUTION_OWNER_KEY="{{.Data.data.DISTRIBUTION_OWNER_KEY}}"
CONSUL_TOKEN="{{.Data.data.CONSUL_TOKEN}}"
{{end}}
Expand All @@ -45,11 +45,11 @@ job "add-scores-live" {
}

env {
PHASE="live"
PHASE="dev"
CONSUL_IP="127.0.0.1"
CONSUL_PORT="8500"
TEST_ACCOUNTS_KEY="facilitator/goerli/live/test-accounts"
DISTRIBUTION_ADDRESS_CONSUL_KEY="smart-contracts/live/distribution-address"
TEST_ACCOUNTS_KEY="facilitator/goerli/dev/test-accounts"
DISTRIBUTION_ADDRESS_CONSUL_KEY="smart-contracts/dev/distribution-address"
}

restart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ job "add-scores-stage" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.23"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npx"]
command = "ts-node"
args = ["scripts/distribution/add-scores.ts"]
Expand Down
2 changes: 1 addition & 1 deletion operations/set-token-distribution-rate-live.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "set-token-distribution-rate-live" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.21"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npx"]
command = "ts-node"
args = ["scripts/distribution/set-token-distribution-rate.ts"]
Expand Down
2 changes: 1 addition & 1 deletion operations/set-token-distribution-rate-stage.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ job "set-token-distribution-rate-stage" {

config {
network_mode = "host"
image = "ghcr.io/ator-development/smart-contracts:0.1.21"
image = "ghcr.io/ator-development/smart-contracts:0.1.24"
entrypoint = ["npx"]
command = "ts-node"
args = ["scripts/distribution/set-token-distribution-rate.ts"]
Expand Down
2 changes: 1 addition & 1 deletion smartweave/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ator/smart-contracts-smartweave",
"version": "0.0.1",
"version": "0.1.24",
"contributors": [
"ATOR Labs",
"Jim Toth <[email protected]>"
Expand Down
112 changes: 112 additions & 0 deletions smartweave/scripts/relay-registry/add-relays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { LoggerFactory, WarpFactory } from 'warp-contracts'
import { EthereumSigner } from 'warp-contracts-plugin-deploy'
import { EthersExtension } from 'warp-contracts-plugin-ethers'
import {
buildEvmSignature,
EvmSignatureVerificationServerPlugin
// @ts-ignore
} from 'warp-contracts-plugin-signature/server'
import { Wallet } from 'ethers'
import Consul from 'consul'
import BigNumber from 'bignumber.js'

import {
AddClaimable,
RelayRegistryHandle,
RelayRegistryState
} from '../../src/contracts'

let contractTxId = ''
const consulToken = process.env.CONSUL_TOKEN
const contractOwnerPrivateKey = process.env.RELAY_REGISTRY_OWNER_KEY

LoggerFactory.INST.logLevel('error')
BigNumber.config({ EXPONENTIAL_AT: 50 })

const warp = WarpFactory
.forMainnet()
.use(new EthersExtension())
.use(new EvmSignatureVerificationServerPlugin())

async function main() {
let consul
if (consulToken) {
const host = process.env.CONSUL_IP,
port = process.env.CONSUL_PORT,
key = process.env.RELAY_REGISTRY_ADDRESS_CONSUL_KEY
if (!host) { throw new Error('CONSUL_IP is not set!') }
if (!port) { throw new Error('CONSUL_PORT is not set!') }
if (!key) { throw new Error('RELAY_REGISTRY_ADDRESS_CONSUL_KEY is not set!') }

console.log(`Connecting to Consul at ${host}:${port}`)
consul = new Consul({ host, port })
const { Value } = await consul.kv.get<{Value: string}>({ token: consulToken, key })
contractTxId = Value
}

if (!contractTxId) {
throw new Error('DISTRIBUTION_CONTRACT_ID is not set!')
}

if (!contractOwnerPrivateKey) {
throw new Error('DISTRIBUTION_OWNER_KEY is not set!')
}

const contract = warp.contract<RelayRegistryState>(contractTxId)
const contractOwner = new Wallet(contractOwnerPrivateKey)

let claims: {address: string, fingerprint: string}[] = []

if (consul) {
const accountsData = await consul.kv.get<{ Value: string }>({
key: process.env.TEST_ACCOUNTS_KEY || 'dummy-path',
token: consulToken
})


if (accountsData) {
const decodedValue = Buffer.from(accountsData.Value, 'base64').toString('utf-8');
const accounts = JSON.parse(decodedValue) as string[];
claims = accounts.map((acct, index, array) => ({
address: acct,
fingerprint: BigNumber(1E39).plus(index).integerValue().toString()
}))

console.log(claims)
}
}

const timestamp = Date.now().toString()

try {
for (let i = 0; i < claims.length; i += 1) {
const input: AddClaimable = {
function: 'addClaimable',
fingerprint: claims[i].fingerprint,
address: claims[i].address,
}

// NB: Sanity check by getting current state and "dry-running" thru contract
// source handle directly. If it doesn't throw, we're good.
const { cachedValue: { state } } = await contract.readState()
RelayRegistryHandle(state, {
input,
caller: contractOwner.address,
interactionType: 'write'
})

// NB: Send off the interaction for real
await contract
.connect({
signer: buildEvmSignature(contractOwner),
type: 'ethereum'
})
.writeInteraction<AddClaimable>(input)
}
} catch(e) {
console.error(e)
console.log("Continuing execution")
}
}

main().catch(error => { console.error(error); process.exitCode = 1; })

0 comments on commit 821cc38

Please sign in to comment.