Skip to content
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
92 changes: 92 additions & 0 deletions src/evm/eth.staking.precompile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,97 @@ describe("Staking precompile", () => {
proxies = await api.query.proxy.proxies(publicKey);
expect(proxies[0].length).to.be.eq(0);
});

});

it("Can get total stake for coldkey", async () => {
await usingEthApi(async (provider) => {
const ss58mirror = convertH160ToSS58(fundedEthWallet.address);
const netuid = 1;

let stakeBefore;
await usingApi(async (api) => {
stakeBefore = u256toBigNumber(
await api.query.subtensorModule.alpha(
hotkey.address,
ss58mirror,
netuid
)
);
});

await usingEthApi(async (provider) => {
// Create a contract instances
const signer = new ethers.Wallet(fundedEthWallet.privateKey, provider);
const contract = new ethers.Contract(
ISTAKING_ADDRESS,
IStakingABI,
signer
);

// Add stake
const tx = await contract.addStake(hotkey.publicKey, netuid, {
value: amountStr,
});
await tx.wait();

await usingApi(async (api) => {
const coldPublicKey = convertH160ToPublicKey(fundedEthWallet.address);
const coldkeyStake = new BigNumber(
await contract.getTotalColdkeyStake(coldPublicKey)
);

// log the coldkey stake
console.log("Coldkey stake: ", coldkeyStake.toString());

expect(coldkeyStake).to.be.bignumber.gt(stakeBefore);
});
});
});
});

it("Can get total stake for hotkey", async () => {
await usingEthApi(async (provider) => {
const ss58mirror = convertH160ToSS58(fundedEthWallet.address);
const netuid = 1;

let stakeBefore;
await usingApi(async (api) => {
stakeBefore = u256toBigNumber(
await api.query.subtensorModule.alpha(
hotkey.address,
ss58mirror,
netuid
)
);
});

await usingEthApi(async (provider) => {
// Create a contract instances
const signer = new ethers.Wallet(fundedEthWallet.privateKey, provider);
const contract = new ethers.Contract(
ISTAKING_ADDRESS,
IStakingABI,
signer
);

// Add stake
const tx = await contract.addStake(hotkey.publicKey, netuid, {
value: amountStr,
});
await tx.wait();

await usingApi(async (api) => {
const hotkeyStake = new BigNumber(
await contract.getTotalHotkeyStake(hotkey.publicKey)
);

// log the hotkey stake
console.log("Hotkey stake: ", hotkeyStake.toString());

expect(hotkeyStake).to.be.bignumber.gt(stakeBefore);
});
});
});
});
});
38 changes: 38 additions & 0 deletions src/util/precompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,44 @@ export const IStakingABI = [
stateMutability: "nonpayable",
type: "function",
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "coldkey",
"type": "bytes32"
}
],
"name": "getTotalColdkeyStake",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "hotkey",
"type": "bytes32"
}
],
"name": "getTotalHotkeyStake",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
];

export const IMetagraphABI = [
Expand Down