Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate multisig #310

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions contracts/commands/contract_management/deploy_multisig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import Archethic, { Utils } from "@archethicjs/sdk"
import config from "../../config.js"
import {
getServiceGenesisAddress,
} from "../utils.js"

import { getDeployTransaction } from "@archethicjs/multisig-sdk"

const command = "deploy_multisig"
const describe = "Deploy multisig for keychain master"
const builder = {
initial_voter: {
describe: "The initial voter address",
demandOption: true, // Required
type: "string"
},
access_seed: {
describe: "The Keychain access seed (default in env config)",
demandOption: false,
type: "string"
},
env: {
describe: "The environment config to use (default to local)",
demandOption: false,
type: "string"
}
}

const handler = async function(argv) {
const envName = argv["env"] ? argv["env"] : "local"
const env = config.environments[envName]

const keychainAccessSeed = argv["access_seed"] ? argv["access_seed"] : env.keychainAccessSeed

if (keychainAccessSeed == undefined) {
console.log("Keychain access seed not defined")
process.exit(1)
}

const initialVoter = argv["initial_voter"]

const archethic = new Archethic(env.endpoint)
await archethic.connect()

let keychain

try {
keychain = await archethic.account.getKeychain(keychainAccessSeed)
} catch (err) {
console.log(err)
process.exit(1)
}

const masterGenesisAddress = getServiceGenesisAddress(keychain, "Master")

const storageNoncePublicKey = await archethic.network.getStorageNoncePublicKey();

const res = keychain.ecEncryptServiceSeed("Master", [storageNoncePublicKey])
const { secret, authorizedPublicKeys: authorizedKeys } = res
console.log("Master genesis address:", masterGenesisAddress)
const index = await archethic.transaction.getTransactionIndex(masterGenesisAddress)

let updateTx = getDeployTransaction(archethic, {
voters: [ initialVoter ],
confirmationThreshold: 1,
}, secret, authorizedKeys)

updateTx = keychain.buildTransaction(updateTx, "Master", index).originSign(Utils.originPrivateKey)

updateTx.on("fullConfirmation", async (_confirmations) => {
const txAddress = Utils.uint8ArrayToHex(updateTx.address)
console.log("Transaction validated !")
console.log("Address:", txAddress)
console.log(env.endpoint + "/explorer/transaction/" + txAddress)
process.exit(0)
}).on("error", (context, reason) => {
console.log("Error while sending transaction")
console.log("Contest:", context)
console.log("Reason:", reason)
process.exit(1)
}).send()
}



export default {
command,
describe,
builder,
handler
}
21 changes: 17 additions & 4 deletions contracts/commands/contract_management/deploy_router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Archethic, { Utils } from "@archethicjs/sdk"
import config from "../../config.js"
import { getRouterCode, getServiceGenesisAddress, sendTransactionWithFunding } from "../utils.js"
import { getRouterCode, getServiceGenesisAddress, sendTransactionWithFunding, sendTransactionWithoutFunding } from "../utils.js"

const command = "deploy_router"
const describe = "Deploy the router"
Expand All @@ -14,6 +14,12 @@ const builder = {
describe: "The environment config to use (default to local)",
demandOption: false,
type: "string"
},
without_funding: {
describe: "Determines if the funding must be disabled",
demandOption: false,
type: "boolean",
default: false
}
}

Expand Down Expand Up @@ -61,9 +67,16 @@ const handler = async function(argv) {

routerTx = keychain.buildTransaction(routerTx, "Router", index).originSign(Utils.originPrivateKey)

sendTransactionWithFunding(routerTx, keychain, archethic)
.then(() => process.exit(0))
.catch(() => process.exit(1))
if (argv["without_funding"]) {
sendTransactionWithoutFunding(routerTx, archethic)
.then(() => process.exit(0))
.catch(() => process.exit(1))
}
else {
sendTransactionWithFunding(routerTx, keychain, archethic)
.then(() => process.exit(0))
.catch(() => process.exit(1))
}
}

export default {
Expand Down
54 changes: 54 additions & 0 deletions contracts/commands/contract_management/get_router_address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Archethic from "@archethicjs/sdk"
import config from "../../config.js"
import {
getServiceGenesisAddress,
} from "../utils.js"

const command = "get_router_address"
const describe = "Get router address"
const builder = {
access_seed: {
describe: "The Keychain access seed (default in env config)",
demandOption: false,
type: "string"
},
env: {
describe: "The environment config to use (default to local)",
demandOption: false,
type: "string"
}
}

const handler = async function(argv) {
const envName = argv["env"] ? argv["env"] : "local"
const env = config.environments[envName]

const keychainAccessSeed = argv["access_seed"] ? argv["access_seed"] : env.keychainAccessSeed

if (keychainAccessSeed == undefined) {
console.log("Keychain access seed not defined")
process.exit(1)
}

const archethic = new Archethic(env.endpoint)
await archethic.connect()

let keychain

try {
keychain = await archethic.account.getKeychain(keychainAccessSeed)
} catch (err) {
console.log(err)
process.exit(1)
}

const routerGenesisAddress = getServiceGenesisAddress(keychain, "Router")
console.log("Router address:", routerGenesisAddress)
}

export default {
command,
describe,
builder,
handler
}
29 changes: 26 additions & 3 deletions contracts/commands/contract_management/update_farm_dates.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Archethic, { Utils } from "@archethicjs/sdk"
import config from "../../config.js"
import { getServiceGenesisAddress } from "../utils.js"
import { getServiceGenesisAddress, sendWithWallet } from "../utils.js"
import { getProposeTransaction } from "@archethicjs/multisig-sdk"

const command = "update_farm_dates"
const describe = "Update the start and end date of a farm"
Expand Down Expand Up @@ -29,7 +30,13 @@ const builder = {
describe: "The environment config to use (default to local)",
demandOption: false,
type: "string"
}
},
with_multisig: {
describe: "Determines if the master is using a multisig",
demandOption: false,
type: "boolean",
default: false
},
}

const handler = async function(argv) {
Expand All @@ -43,7 +50,10 @@ const handler = async function(argv) {
process.exit(1)
}

const archethic = new Archethic(env.endpoint)
const archethic = new Archethic(argv["with_multisig"] ? undefined : env.endpoint)
if (archethic.rpcWallet) {
archethic.rpcWallet.setOrigin({ name: "Archethic DEX CLI" });
}
await archethic.connect()

let keychain
Expand All @@ -63,6 +73,19 @@ const handler = async function(argv) {
console.log("Master genesis address:", masterGenesisAddress)
const index = await archethic.transaction.getTransactionIndex(masterGenesisAddress)

if (argv["with_multisig"]) {
const updateTx = getProposeTransaction(archethic, masterGenesisAddress, {
recipients: [
{ address: farmAddress, action: "update_dates", args: [startDate, endDate] }
]
})
sendWithWallet(updateTx, archethic)
.then(() => process.exit(0))
.catch(() => process.exit(1))

return
}

let updateTx = archethic.transaction.new()
.setType("transfer")
.addRecipient(farmAddress, "update_dates", [startDate, endDate])
Expand Down
29 changes: 26 additions & 3 deletions contracts/commands/contract_management/update_farms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Archethic, { Utils } from "@archethicjs/sdk"
import config from "../../config.js"
import { getServiceGenesisAddress } from "../utils.js"
import { getServiceGenesisAddress, sendWithWallet } from "../utils.js"
import { getProposeTransaction } from "@archethicjs/multisig-sdk"

const command = "update_farms"
const describe = "Update all farm code"
Expand All @@ -14,7 +15,13 @@ const builder = {
describe: "The environment config to use (default to local)",
demandOption: false,
type: "string"
}
},
with_multisig: {
describe: "Determines if the master is using a multisig",
demandOption: false,
type: "boolean",
default: false
},
}

const handler = async function(argv) {
Expand All @@ -28,7 +35,10 @@ const handler = async function(argv) {
process.exit(1)
}

const archethic = new Archethic(env.endpoint)
const archethic = new Archethic(argv["with_multisig"] ? undefined : env.endpoint)
if (archethic.rpcWallet) {
archethic.rpcWallet.setOrigin({ name: "Archethic DEX CLI" });
}
await archethic.connect()

let keychain
Expand All @@ -52,6 +62,19 @@ const handler = async function(argv) {
console.log("Master genesis address:", masterGenesisAddress)
const index = await archethic.transaction.getTransactionIndex(masterGenesisAddress)

if (argv["with_multisig"]) {
const updateTx = getProposeTransaction(archethic, masterGenesisAddress, {
recipients: [
{ address: routerGenesisAddress, action: "update_farms_code" }
]
})
sendWithWallet(updateTx, archethic)
.then(() => process.exit(0))
.catch(() => process.exit(1))

return
}

let updateTx = archethic.transaction.new()
.setType("transfer")
.addRecipient(routerGenesisAddress, "update_farms_code")
Expand Down
29 changes: 26 additions & 3 deletions contracts/commands/contract_management/update_lp_fee.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Archethic, { Utils } from "@archethicjs/sdk"
import config from "../../config.js"
import { getServiceGenesisAddress } from "../utils.js"
import { getServiceGenesisAddress, sendWithWallet } from "../utils.js"
import { getProposeTransaction } from "@archethicjs/multisig-sdk"

const command = "update_lp_fee"
const describe = "Update the liquidity provider fee for a pool"
Expand All @@ -24,7 +25,13 @@ const builder = {
describe: "The environment config to use (default to local)",
demandOption: false,
type: "string"
}
},
with_multisig: {
describe: "Determines if the master is using a multisig",
demandOption: false,
type: "boolean",
default: false
},
}

const handler = async function(argv) {
Expand All @@ -38,7 +45,10 @@ const handler = async function(argv) {
process.exit(1)
}

const archethic = new Archethic(env.endpoint)
const archethic = new Archethic(argv["with_multisig"] ? undefined : env.endpoint)
if (archethic.rpcWallet) {
archethic.rpcWallet.setOrigin({ name: "Archethic DEX CLI" });
}
await archethic.connect()

let keychain
Expand All @@ -57,6 +67,19 @@ const handler = async function(argv) {
console.log("Master genesis address:", masterGenesisAddress)
const index = await archethic.transaction.getTransactionIndex(masterGenesisAddress)

if (argv["with_multisig"]) {
const updateTx = getProposeTransaction(archethic, masterGenesisAddress, {
recipients: [
{ address: poolAddress, action: "set_lp_fee", args: [newFee] }
]
})
sendWithWallet(updateTx, archethic)
.then(() => process.exit(0))
.catch(() => process.exit(1))

return
}

let updateTx = archethic.transaction.new()
.setType("transfer")
.addRecipient(poolAddress, "set_lp_fee", [newFee])
Expand Down
Loading