Skip to content

Delegating

Stakers and traders can delegate the following actions to other accounts

  • Burning (unstaking)
  • Claiming
  • Issuance (staking)
  • Trading (exchanging)
  • (All of the above)

Adding Approval API

Contract

Contract (address & ABI): DelegateApprovals

Methods

Events Emitted

On a successful transaction, the following events occur:

name emitted on address authoriser address delegate bytes32 action
Approval DelegateApprovals msg.sender delegate One of ApproveAll, BurnForAddress, ClaimForAddress, IssueForAddress, ExchangeForAddress

Examples from Mainnet

  • DelegateApprovals.approveAllDelegatePowers(0xf70c)
  • DelegateApprovals.approveClaimOnBehalf(0xa2979)

Withdrawing Approval API

Contract

Contract (address & ABI): DelegateApprovals

Methods

Events Emitted

On a successful transaction, the following events occur:

name emitted on address authoriser address delegate bytes32 action
WithdrawApproval DelegateApprovals msg.sender delegate One of ApproveAll, BurnForAddress, ClaimForAddress, IssueForAddress, ExchangeForAddress

Code Snippets

Delegating

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { SynthetixJs } = require('synthetix-js');
const privateKey = '0x' + '1'.repeat(64); // don't actually put a private key in code obviously

// parameters: default provider, default networkId, private key as a string
const networkId = 3; // ropsten, (use 1 for mainnet)
const signer = new SynthetixJs.signers.PrivateKey(null, networkId, privateKey);
const snxjs = new SynthetixJs({ signer, networkId });

(async () => {
  try {
    const contractAddress = '0x0000000000000000000000000000000000000000';

    // send transaction
    const txn = await snxjs.DelegateApprovals.approveAllDelegatePowers(contractAddress);

    console.log('hash is mining', txn.hash);

    // wait for mining
    await txn.wait();

    // fetch logs of transaction
    const { logs } = await signer.provider.getTransactionReceipt(txn.hash);

    // show them
    console.log(JSON.stringify(logs, null, '\t'));
  } catch (err) {
    console.log('Error', err);
  }
})();
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const synthetix = require('synthetix'); // nodejs
const ethers = require('ethers'); // nodejs
// or using ES modules:
// import synthetix from 'synthetix';
// import ethers from 'ethers';

const network = 'ropsten';
const provider = ethers.getDefaultProvider(network === 'mainnet' ? 'homestead' : network);

const { abi } = synthetix.getSource({ network, contract: 'DelegateApprovals' });
const { address } = synthetix.getTarget({ network, contract: 'DelegateApprovals' });

const privateKey = '0x' + '1'.repeat(64); // don't actually put a private key in code obviously
const signer = new ethers.Wallet(privateKey).connect(provider);

// see https://docs.ethers.io/ethers.js/html/api-contract.html#connecting-to-existing-contracts
const DelegateApprovals = new ethers.Contract(address, abi, signer);

(async () => {
  try {
    const contractAddress = '0x0000000000000000000000000000000000000000';

    // send transaction
    const txn = await DelegateApprovals.approveAllDelegatePowers();
    // wait for mining
    await txn.wait();
    // fetch logs of transaction
    const { logs } = await provider.getTransactionReceipt(txn.hash);
    // display
    console.log(JSON.stringify(logs, null, '\t'));
  } catch (err) {
    console.log('Error', err);
  }
})();

No delegation in Solidity directly

Note: due to how calling works in Solidity, users must invoke these delegation functions themselves directly with the address of your contracts - the calling of these functions cannot be delegated themselves inside of Solidity. This is similar to how ERC20 approvals work (users must approve a contract to be able to transfer their tokens).