-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(staking): add BTC support (#60)
- Loading branch information
Showing
13 changed files
with
442 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ethers } from "ethers"; | ||
|
||
export const convertToHexAddress = (address: string): string => { | ||
let addr: string; | ||
try { | ||
// Check if it's a valid hex address | ||
addr = ethers.utils.getAddress(address); | ||
} catch (e) { | ||
// If not, try to convert it to an address from bech32 | ||
addr = ("0x" + Buffer.from(address).toString("hex")).slice(0, 42); | ||
} | ||
return addr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { task } from "hardhat/config"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { utils } from "ethers"; | ||
|
||
const main = async (args: any, hre: HardhatRuntimeEnvironment) => { | ||
const dataTypes = ["bytes"]; | ||
const values = [utils.toUtf8Bytes(args.address)]; | ||
|
||
const encodedData = utils.solidityPack(dataTypes, values); | ||
console.log(`Encoded: ${encodedData}`); | ||
console.log(`context.origin: ${encodedData.slice(0, 42)}`); | ||
}; | ||
|
||
task( | ||
"address", | ||
"Encode a Bitcoin bech32 address to hex", | ||
main | ||
).addPositionalParam("address"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { task } from "hardhat/config"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { parseEther } from "@ethersproject/units"; | ||
import { getAddress } from "@zetachain/protocol-contracts"; | ||
import { prepareData, trackCCTX } from "@zetachain/toolkit/helpers"; | ||
|
||
const main = async (args: any, hre: HardhatRuntimeEnvironment) => { | ||
const [signer] = await hre.ethers.getSigners(); | ||
console.log(`🔑 Using account: ${signer.address}\n`); | ||
|
||
const data = prepareData( | ||
args.contract, | ||
["uint8", "address"], | ||
["3", args.beneficiary] | ||
); | ||
const to = getAddress("tss", hre.network.name); | ||
const value = parseEther("0"); | ||
|
||
const tx = await signer.sendTransaction({ data, to, value }); | ||
console.log(` | ||
🚀 Successfully broadcasted a token transfer transaction on ${hre.network.name} network. | ||
📝 Transaction hash: ${tx.hash} | ||
`); | ||
await trackCCTX(tx.hash); | ||
}; | ||
|
||
task( | ||
"set-beneficiary", | ||
"Set the address on ZetaChain which will be allowed to claim staking rewards", | ||
main | ||
) | ||
.addParam("contract", "The address of the contract on ZetaChain") | ||
.addPositionalParam("beneficiary", "The address of the beneficiary"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.