-
Notifications
You must be signed in to change notification settings - Fork 2
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
Acre SDK - staking module #106
Commits on Feb 7, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 8609c2d - Browse repository at this point
Copy the full SHA 8609c2dView commit details -
Create wrappers for some of objects from `@keep-network/tbtc-v2.ts` lib to use in Acre SDK.
Configuration menu - View commit details
-
Copy full SHA for 6cf049a - Browse repository at this point
Copy the full SHA 6cf049aView commit details -
Configuration menu - View commit details
-
Copy full SHA for c84ba51 - Browse repository at this point
Copy the full SHA c84ba51View commit details -
Create
ChainMessages
interfaceThe main idea is to hide the signing process under the exact implementation for a given chain. For example, we can use `ethers` lib for Ethereum implementation, but different lib for other chains. The Acre staking flow will require a signature and the signig message implementation will be used in the staking module.
Configuration menu - View commit details
-
Copy full SHA for 7a1619d - Browse repository at this point
Copy the full SHA 7a1619dView commit details -
Create a module that is responsible for initializing a stake for a receiver via tBTC depositor contract from `Acre`.
Configuration menu - View commit details
-
Copy full SHA for 155ce60 - Browse repository at this point
Copy the full SHA 155ce60View commit details -
Add
initializeEthereum
to theAcre
main classThis function is responsible for creating the `Acre` SDK for any `Ethereum` network. It also creates necessary modules that allow developers to interact with Acre system.
Configuration menu - View commit details
-
Copy full SHA for 936c90e - Browse repository at this point
Copy the full SHA 936c90eView commit details -
Add
ethers
lib to the SDK moduleWe want to build the Ethereum implementation on top of the `ethers` lib.
Configuration menu - View commit details
-
Copy full SHA for d298630 - Browse repository at this point
Copy the full SHA d298630View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8cad4de - Browse repository at this point
Copy the full SHA 8cad4deView commit details -
Update chain messages interface
Add `ChainSignedMessage` that represents a signature. This interface exposes `verify` function that returns an address of the private key that produced the signature. Also here we update the `ChainMessages` interface - `sign` function should return the `ChainSignedMessage` object.
Configuration menu - View commit details
-
Copy full SHA for 181b266 - Browse repository at this point
Copy the full SHA 181b266View commit details -
Add Ethereum implementation of messages
Implement signing process for Ethereum chain. Here we use the `ethers` lib under the hood.
Configuration menu - View commit details
-
Copy full SHA for 91d4e42 - Browse repository at this point
Copy the full SHA 91d4e42View commit details -
Add
receiver
validation tostake
functionWe make sure that the `receiver` address is equal to the address that produced the signature.
Configuration menu - View commit details
-
Copy full SHA for 20d6a83 - Browse repository at this point
Copy the full SHA 20d6a83View commit details -
We need types generated by typechain tool.
Configuration menu - View commit details
-
Copy full SHA for d877929 - Browse repository at this point
Copy the full SHA d877929View commit details -
Create Ethereum contract wrapper
Create Ethereum contract wrapper using ethers. We do not want to expose ethers contract instance outside the SDK.
Configuration menu - View commit details
-
Copy full SHA for 4e70b9c - Browse repository at this point
Copy the full SHA 4e70b9cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 0aa1ce3 - Browse repository at this point
Copy the full SHA 0aa1ce3View commit details -
We should use our wrappers because we expose them outside the SDK.
Configuration menu - View commit details
-
Copy full SHA for 7fc2f8b - Browse repository at this point
Copy the full SHA 7fc2f8bView commit details -
`Staking` -> `StakeInitialization`. The previous name was confusing - we want to name classes as steps of the staking flow to make the sdk more dev-friendly.
Configuration menu - View commit details
-
Copy full SHA for 48d3c4b - Browse repository at this point
Copy the full SHA 48d3c4bView commit details -
To simplify accept `Signer` or `VoidSigner` only. Developers can use `VoidSigner` from `ethers` if they want to initialize the Ethereum Acre SDK in readonly mode instead of `Provider`.
Configuration menu - View commit details
-
Copy full SHA for 22e6493 - Browse repository at this point
Copy the full SHA 22e6493View commit details -
Use
jest
instead ofchai
andmocha
`Jest` testing framework has built-in support for mocks, stubs, and spies. Chai requires the installation of additional dependencies but most of them are no longer maintained. I also tried using the `chai` with `ethereum-waffle` package, that adds support for mocking contracts, but it only supports ethers in v5, we want to use the latest version of ethers - it is v6.
Configuration menu - View commit details
-
Copy full SHA for e92448c - Browse repository at this point
Copy the full SHA e92448cView commit details -
Configuration menu - View commit details
-
Copy full SHA for ab32db3 - Browse repository at this point
Copy the full SHA ab32db3View commit details -
Configuration menu - View commit details
-
Copy full SHA for dd89d50 - Browse repository at this point
Copy the full SHA dd89d50View commit details -
Add unit test for `EthereumTBTCDepositor.initializeStake` function.
Configuration menu - View commit details
-
Copy full SHA for 5273564 - Browse repository at this point
Copy the full SHA 5273564View commit details -
Configuration menu - View commit details
-
Copy full SHA for 15aebb1 - Browse repository at this point
Copy the full SHA 15aebb1View commit details -
Add support for eip-712 typed messages
The staking flow in Acre will require the typed messages so here we rename the `ChainMessageSigner` to `ChainEIP712Signer`. The Ethereum implementation uses the ethers lib to handle the signing and verifying process.
Configuration menu - View commit details
-
Copy full SHA for e97b2a5 - Browse repository at this point
Copy the full SHA e97b2a5View commit details -
Add `receiver` and `referral` params to the `initializeStake` function. We need to pass these values as parsed hex as extra data to the tBTC system. Currently left only TODO because we need to wait for extra data feature in tbtc-v2.ts lib. Also we decided to not include the signing process here but the `StakeInitialization` should be responsible for this.
Configuration menu - View commit details
-
Copy full SHA for a4acb89 - Browse repository at this point
Copy the full SHA a4acb89View commit details -
Rename `getDepositAddress` -> `getBitcoinAddress` to better understand what type of address it is. It should be called as first step of the staking to get the Bitcoin address and send a given amount of BTC to a received address.
Configuration menu - View commit details
-
Copy full SHA for 230041f - Browse repository at this point
Copy the full SHA 230041fView commit details -
Update
StakeInitialization
constructorAdd `receiver` and `referral` those values should be stored in this object to not pass them again to the `stake` function. Also here we update the type of `messageSigner`.
Configuration menu - View commit details
-
Copy full SHA for d791c5c - Browse repository at this point
Copy the full SHA d791c5cView commit details -
Add
signMessage
step toStakeInitialization
User shuold sign message before the stake. We decided to implelemnt it as a separate function that should be called before stake because we want to give developers more flexibility. It's not a part of `stake` function because e.g. in the dapp after signing message there may be some additional steps. After signing we save the signed message in the instance of `StakeInitialization` which then can be used inside `stake` function w/o passing message to this function.
Configuration menu - View commit details
-
Copy full SHA for 85cb2e7 - Browse repository at this point
Copy the full SHA 85cb2e7View commit details -
Add unit test for staking module
Clean up tests by extracting test data to variables outside of the tests brackets. Add unit test for `StakeInitialization` object which is created by `StakingModule.initializeStake`.
Configuration menu - View commit details
-
Copy full SHA for 08b0872 - Browse repository at this point
Copy the full SHA 08b0872View commit details -
Update
test
script in sdkpackage.json
Use `--verbose` flag to display individual test results with the test suite hierarchy.
Configuration menu - View commit details
-
Copy full SHA for 7baf424 - Browse repository at this point
Copy the full SHA 7baf424View commit details -
`message-signer` -> `eip712-signer`. The staking flow will require only eip712 typed messages so we decided to rename to a more specific name.
Configuration menu - View commit details
-
Copy full SHA for 961c5e2 - Browse repository at this point
Copy the full SHA 961c5e2View commit details -
Configuration menu - View commit details
-
Copy full SHA for fcb76d3 - Browse repository at this point
Copy the full SHA fcb76d3View commit details -
Add unit test for Ethereum implementation of ChainSignedMessage.
Configuration menu - View commit details
-
Copy full SHA for f264667 - Browse repository at this point
Copy the full SHA f264667View commit details -
Add Bitcoin refund account property to stake msg
Also leave a `TODO` not to revisit the message structure before the launch.
Configuration menu - View commit details
-
Copy full SHA for b4fcf06 - Browse repository at this point
Copy the full SHA b4fcf06View commit details -
Leave
TODO
comment instake
fnCurrently to do not block the integration SDK <-> dApp we want to send Ethereum transaction as part of the staking flow. In the final version users won't have to sign the Ethereum transaction, they will just send stake details to a relayer bot which will stake BTC on user's behalf.
Configuration menu - View commit details
-
Copy full SHA for 1103d0e - Browse repository at this point
Copy the full SHA 1103d0eView commit details -
Add fn to initialize the Acre SDK for Ethereum
Based on the network param this function creates Acre SDK for supported Ethereum networks eg. `mainnet` or `sepolia`. Here we leave few TODOs that we should handle later once we get contract artifacts for different networks. Also we need to make sure the tBTC SDK will work ok with ethers v6 - we will check this while working on poc for Acre SDK and dApp integration.
Configuration menu - View commit details
-
Copy full SHA for 497e44e - Browse repository at this point
Copy the full SHA 497e44eView commit details -
Update
EthereumEIP712Signer
implementationGet the chain id from `ethers.provider` instead of passing it to a `sign` fn in `domain` param. The main idea is to not expose chain-specific API outside the lib components. Modules should not know about ethers lib.
Configuration menu - View commit details
-
Copy full SHA for 3d98e48 - Browse repository at this point
Copy the full SHA 3d98e48View commit details -
Cover a case when ethers provider can not return chain id.
Configuration menu - View commit details
-
Copy full SHA for e8d7d37 - Browse repository at this point
Copy the full SHA e8d7d37View commit details -
Add docs comments to TBTCDepositor interface and to the Ethereum implementation of this contract.
Configuration menu - View commit details
-
Copy full SHA for 9317fb3 - Browse repository at this point
Copy the full SHA 9317fb3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 53fa13a - Browse repository at this point
Copy the full SHA 53fa13aView commit details -
Add docs comments to eip-712 signer
Add docs comments to abstract interfaces and to Ethereum implementation.
Configuration menu - View commit details
-
Copy full SHA for 0ba2893 - Browse repository at this point
Copy the full SHA 0ba2893View commit details -
Configuration menu - View commit details
-
Copy full SHA for bd7d335 - Browse repository at this point
Copy the full SHA bd7d335View commit details -
Configuration menu - View commit details
-
Copy full SHA for c9020fd - Browse repository at this point
Copy the full SHA c9020fdView commit details -
Fix linting errors in SDK tests
Here we also disable `@typescript-eslint/unbound-method` rule for test files because it reporst that we use unbonded method for `expect` function from jest. For example, with this rule we can't do the following check: ``` expect(...).toBeDefined() ```
Configuration menu - View commit details
-
Copy full SHA for 614cf75 - Browse repository at this point
Copy the full SHA 614cf75View commit details -
The tBTC-v2.ts SDK uses the ethers v5 and signers are not compatible with signers from ethers v6. Here we create an abstract signer that adds necessary methods (only used by tBTC-v2 SDK) to be compatible with ethers v5 signer which is used in the tBTC-v2.ts SDK.
Configuration menu - View commit details
-
Copy full SHA for bc4ec4c - Browse repository at this point
Copy the full SHA bc4ec4cView commit details -
Use `EthereumSignerCompatibleWithEthersV5` type for `signer` param to force developers to pass signer compatible with signer used in tbtc-v2.ts SDK. Thansk to this we can pass signer from ethers v6 but it must implements necessary functions or extends `EthereumSignerCompatibleWithEthersV5` abstract class.
Configuration menu - View commit details
-
Copy full SHA for ee03ee9 - Browse repository at this point
Copy the full SHA ee03ee9View commit details -
Configuration menu - View commit details
-
Copy full SHA for f4e6dc9 - Browse repository at this point
Copy the full SHA f4e6dc9View commit details -
Disble rule for import in
tbtc-depositor.ts
fileDisable `import/no-unresolved` and leave a `TODO` to fix this issue. Disabling this rule for now because probably the path will change once we publish npm package for `core` module.
Configuration menu - View commit details
-
Copy full SHA for c7941c9 - Browse repository at this point
Copy the full SHA c7941c9View commit details -
Fix Ethereum implementation of
initializeStake
The ethers contract expects the address in prefixed format so we must add `0x` prefix. I've updated unit tests in one of the previous commits.
Configuration menu - View commit details
-
Copy full SHA for 0cdd4c5 - Browse repository at this point
Copy the full SHA 0cdd4c5View commit details -
Configuration menu - View commit details
-
Copy full SHA for d732d77 - Browse repository at this point
Copy the full SHA d732d77View commit details -
`depositor` -> `tbtcDepositor` to match the contract name.
Configuration menu - View commit details
-
Copy full SHA for c12643d - Browse repository at this point
Copy the full SHA c12643dView commit details -
Clearly specify the return type
Specify the return type of the private static method in Acre class.
Configuration menu - View commit details
-
Copy full SHA for d0e121d - Browse repository at this point
Copy the full SHA d0e121dView commit details -
Rename class field and constructor param
`messages` -> `messageSigner`.
Configuration menu - View commit details
-
Copy full SHA for 26389b0 - Browse repository at this point
Copy the full SHA 26389b0View commit details -
We would require this account to sign the messages, so it makes more sense to name it `staker` rather than `receiver`.
Configuration menu - View commit details
-
Copy full SHA for 977062b - Browse repository at this point
Copy the full SHA 977062bView commit details -
Use `TbtcDeposit` alias for `Deposit` import and rename the field in the `StakeInitialization` class to `tbtcDepositor`. To indicate this is deposit from tbtc-v2.ts SDK.
Configuration menu - View commit details
-
Copy full SHA for 46fa436 - Browse repository at this point
Copy the full SHA 46fa436View commit details -
Set correct contract name in typed message
The contract name is `TbtcDepositor` not `TBTCDepositor`.
Configuration menu - View commit details
-
Copy full SHA for 239d6ec - Browse repository at this point
Copy the full SHA 239d6ecView commit details -
Update the staking message format
The message should contain the Bitcoin recovery address instead of the public key hash of this address.
Configuration menu - View commit details
-
Copy full SHA for 05a22f6 - Browse repository at this point
Copy the full SHA 05a22f6View commit details -
Bump tbtc-v2.ts lib to the latest version
The latest version of the `tbtc-v2.ts` lib adds support for revealing deposit with extra data. We need this feature to stake BTC(tBTC) on user's behalf.
Configuration menu - View commit details
-
Copy full SHA for 1c24521 - Browse repository at this point
Copy the full SHA 1c24521View commit details -
Update the
TBTCDepositor
interfaceThe `TBTCDepositor` should implement the `DepositorProxy` interface to reveal the deposit with extra data on user's behalf. Here we also add `encodeExtraData` and `decodeExtraData` functions to encodes and decodes extra data passed to the tBTC Bridge contract. The Acre extra data is staker address and referral number.
Configuration menu - View commit details
-
Copy full SHA for 1e91791 - Browse repository at this point
Copy the full SHA 1e91791View commit details -
Adujst staking module to the new TBTCDepositor interface and the latest version of the `tbtc-v2.ts` lib. We need to initiate the deposit with extra data using the `tbtc-v2.ts` SDK by injecting our implementation of the `DepositorProxy`.
Configuration menu - View commit details
-
Copy full SHA for 968bdf7 - Browse repository at this point
Copy the full SHA 968bdf7View commit details -
Update staking module unit test
Adjust unit tests to the latest version of tbtc-v2.ts lib that adds support for revealing deposits with extra data via depositor proxy.
Configuration menu - View commit details
-
Copy full SHA for bbf93ff - Browse repository at this point
Copy the full SHA bbf93ffView commit details -
We can get the referral and staker from tBTC deposit object.
Configuration menu - View commit details
-
Copy full SHA for 54dabd2 - Browse repository at this point
Copy the full SHA 54dabd2View commit details -
Expose shared components, feature modules and the `Acre` entry point class from the root `index.ts` file. The `Acre` entry point class currently provides static function to initialize the Acre SDK for Ethereum network.
Configuration menu - View commit details
-
Copy full SHA for a59aa37 - Browse repository at this point
Copy the full SHA a59aa37View commit details -
Update message signing process in stake flow
Pass the `bitcoinRecoveryAddress` to the `StakeInitialization` class. Since we can't easily determine if we should use `true` or `false` in `BitcoinAddressConverter.publicKeyHashToAddress` to convert public key hash to `P2PKH` or `P2WPKH` we can use what the input was w/o doing a conversion. Here we also get rid of: - the bitcoin client from the `StakeInitailization` class because at least for now it is unnecessary, - `referral` field - it is decoded and passed to the contract function under the hood.
Configuration menu - View commit details
-
Copy full SHA for d29e0fb - Browse repository at this point
Copy the full SHA d29e0fbView commit details -
We need `build` and `typechain` artifacts from `core` package in `sdk` because we import artifacts and types generated by `typechain` in `sdk` package. To achieve this, we extract a reusable workflow that builds the `core` package and uploads necessary artifacts. Then we use this reusable workflow to run successfully the `sdk` jobs. Here we also update the `jest` config - we should ignore tests inside `dist` dir if exists.
Configuration menu - View commit details
-
Copy full SHA for df85827 - Browse repository at this point
Copy the full SHA df85827View commit details -
Add comment to describe why we omit field
We want to omit the `signerOrProvider` because it points to ethers v5. We use ethers v6 in Acre SDK.
Configuration menu - View commit details
-
Copy full SHA for 565a0a1 - Browse repository at this point
Copy the full SHA 565a0a1View commit details -
Update root
.prettierignore
fileIgnore `sdk` monorepo package - `sdk` package has own prettier config.
Configuration menu - View commit details
-
Copy full SHA for 10d4bec - Browse repository at this point
Copy the full SHA 10d4becView commit details -
Fix variable type in
encodeExtraData
fnAccording to the contract source code, the referral should be `uint16`. Here we also add more unit tests to cover more cases eg. when a referral is `0` (min `uint16`) and `65535` (max `uint16`).
Configuration menu - View commit details
-
Copy full SHA for d846701 - Browse repository at this point
Copy the full SHA d846701View commit details -
Remove
Goerli
from supported Ethereum networksWe do not expect to support it.
Configuration menu - View commit details
-
Copy full SHA for 06b7617 - Browse repository at this point
Copy the full SHA 06b7617View commit details -
Add artifacts deployed on Sepolia to SDK
And create the ethereum contract instance based on this artifact.
Configuration menu - View commit details
-
Copy full SHA for 8b202b8 - Browse repository at this point
Copy the full SHA 8b202b8View commit details -
Configuration menu - View commit details
-
Copy full SHA for e037f64 - Browse repository at this point
Copy the full SHA e037f64View commit details -
Imporve the stake message template
`receiver` -> `ethereumStakerAddress`. Add more context to the name of field for clarity when user sees it on the device, so they know what the value means.
Configuration menu - View commit details
-
Copy full SHA for ef9d7ee - Browse repository at this point
Copy the full SHA ef9d7eeView commit details -
Validate if
staker
is a valid ethereum addressCheck if the staker address is a valid ethereum and non-zero address.
Configuration menu - View commit details
-
Copy full SHA for 96101e2 - Browse repository at this point
Copy the full SHA 96101e2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4bba1bd - Browse repository at this point
Copy the full SHA 4bba1bdView commit details -
Configuration menu - View commit details
-
Copy full SHA for faa487c - Browse repository at this point
Copy the full SHA faa487cView commit details -
Update the
StakeInitialization
constructorPass the `staker` value the same as was used in this function input parameter and use it insied `StakeInitialization` constructor to initialize the value of `#staker` field, instead of recovering it from the ` _tbtcDeposit.getReceipt()` extra data, as this is an external library that can be compromised and return invalid value.
Configuration menu - View commit details
-
Copy full SHA for 07e83b0 - Browse repository at this point
Copy the full SHA 07e83b0View commit details