Skip to content

Commit

Permalink
Add "transfer-proxy" command for L1
Browse files Browse the repository at this point in the history
  • Loading branch information
resonant-riches committed Jan 29, 2024
1 parent cc68301 commit 97a1fc0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ For the full documentation, please install the cli and explore the commands and
* `spawn-proxy` - Sets the spawn-proxy address for the points.
* `network-key` - Sets the network keys for the points, which is required to be able to boot the Urbit.
* `transfer` - Transfers the point to a target address or the wallet files.
* `transfer-proxy` - Sets the transfer proxy address for the points.
* `modify-l2` - Modifies the state of one or more points via a L2 roller. The roller then submits the changes to the L2 Ethereum contract. Any point modified via this command, needs to be on L2.
* `spawn` - Spawns multiple points to the supplied address. The galaxy or star that spawns needs to be on L2 or the spawn proxy needs to be on L2.
* `management-proxy` - Sets the management proxy address for the points.
Expand Down
54 changes: 54 additions & 0 deletions cmds/modify-l1_cmds/transfer-proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const ob = require('urbit-ob')
const ajs = require('azimuth-js')
const _ = require('lodash')
const {files, validate, eth, azimuth, findPoints} = require('../../utils')

exports.command = 'transfer-proxy'
exports.desc = 'Set the transfer proxy of one or more points.'

exports.builder = function(yargs) {
}

exports.handler = async function (argv)
{
const workDir = files.ensureWorkDir(argv.workDir);
const privateKey = await eth.getPrivateKey(argv);
const ctx = await eth.createContext(argv);
const ethAccount = eth.getAccount(ctx.web3, privateKey);

const wallets = argv.useWalletFiles ? findPoints.getWallets(workDir) : null;
const points = findPoints.getPoints(argv, workDir, wallets);

console.log(`Will set transfer proxy for ${points.length} points`);
for (const p of points)
{
let patp = ob.patp(p);
console.log(`Trying to set transfer proxy for ${patp} (${p}).`);

let wallet = argv.useWalletFiles ? wallets[patp] : null;
let targetAddress =
argv.address != undefined
? argv.address
: argv.useWalletFiles
? wallet.ownership.keys.address :
null; //fail
targetAddress = validate.address(targetAddress, true);

if(await azimuth.isTransferProxy(ctx.contracts, p, targetAddress)){
console.log(`Target address ${targetAddress} is already transfer proxy for ${patp}.`);
continue;
}

var res = await ajs.check.canSetTransferProxy(ctx.contracts, p, ethAccount.address);
if(!res.result){
console.log(`Cannot set transfer proxy for ${patp}: ${res.reason}`);
continue;
}

//create and send tx
let tx = ajs.ecliptic.setTransferProxy(ctx.contracts, p, targetAddress)
await eth.setGasSignSendAndSaveTransaction(ctx, tx, privateKey, argv, workDir, patp, 'transferproxy');
} //end for each point

process.exit(0);
};

0 comments on commit 97a1fc0

Please sign in to comment.