@pier-wallet/contracts
v0.24.0
Published
pier wallet smart wallet and integration contracts
Downloads
10
Readme
Contracts
Project setup
- Copy
.env.sample
to.env
and fill in all the required variables. You will get an error if you don't specify all required env variables. - Run
yarn
to install dependencies - Run
yarn dev:build
to setup the project.
Serve local blockchain with deployed contracts
Starts a fork of harmony mainnet on http://localhost:8545 and deploys all contracts. The addresses of smart contracts should not change, unless the deploy scripts are changed.
yarn dev:serve
Running tests
yarn test:unit
If in doubt - run yarn dev:typechain
Deployment
Deploy: Available networks:
localhost
harmonytestnet
polygontestnet
bsctestnet
fantomtestnet
harmonymainnet
polygonmainnet
bscmainnet
fantommainnet
yarn deploy:wallet-factory --network [network] --gasprice [gas price in wei]
yarn deploy:v3 --network [network] --gasprice [gas price in wei]
yarn deploy:periphery --network [network] --gasprice [gas price in wei]
yarn deploy:products --network [network] --gasprice [gas price in wei]
Post Deploy
Build NPM Package
for testnet: preid= alpha
npm version patch/minor/major [prerelease --preid=...]
To verify on explorer
yarn hardhat verify --network harmonymainnet [contract address]
Close PR!
Wallet Upgrade
- Put all upgrades of the wallet into /contracts/wallets/ folder with naming convention SmartWallet[VERSION]
- Inherit the latest version in the new Wallet:
contract SmartWallet[NEW_VERSION] is SmartWallet[PREVIOUS_VERSION] {...}
IF
- you need to DECLARE new variables - declare them
- you need to INITIALIZE new variables - add function to initialize and call on upgrade [WORKAROUND / TO BE FIXED WITH WALLET_FACTORY UPGRADE]
- you need to DECLARE new functions - declare them
In any case
- SET the new version function:
function version() external pure override returns (uint256) {
return [NEW_VERSION]
}
- CREATE deployment script for NEW_VERSION in /deploy with naming convention [+increment]_deploy_v[NEW_VERSION].ts
- UPDATE in new deployment script the deploy.tags to [NEW_VERSION] (e.g. "v2")
- UPDATE package.json script to
deploy:v[NEW_VERSION]: ".... --tags v[NEW_VERSION]"
- CREATE new Entry in test/otpWallet.test.ts [TODO: TO BE FIXED / NOT YET WORKING]
const SMART_WALLET_CONTRACTS_MAP = [
...PREVIOUS_VERSIONS,
{
name: SmartWallet[NEW_VERSION],
version: [NEW_VERSION],
},
] as const;
Wallet Factory Upgrade
Product Reference Data
do this on etherscan / polygonscan / etc
Calculate percentages, then on ..scan, add. Example:
[
["0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6", 500000000000],
["0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619", 200000000000],
["0x7DfF46370e9eA5f0Bad3C4E29711aD50062EA7A4", 100000000000],
["0xeCDCB5B88F8e3C15f95c720C51c71c9E2080525d", 150000000000],
["0xB85517b87BF64942adf3A0B9E4c71E4Bc5Caa4e5", 50000000000]
]
OR
[
{
"token": "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
"percentage": 500000000000
},
{
"token": "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
"percentage": 200000000000
},
{
"token": "0x7DfF46370e9eA5f0Bad3C4E29711aD50062EA7A4",
"percentage": 100000000000
},
{
"token": "0xeCDCB5B88F8e3C15f95c720C51c71c9E2080525d",
"percentage": 150000000000
},
{
"token": "0xB85517b87BF64942adf3A0B9E4c71E4Bc5Caa4e5",
"percentage": 50000000000
}
]
To set the Management fee (e.g. 2% per annum):
Calculate hourly management Fee using wolfram alpha
(1-x)^(24*365) = (1-0.02) Where 0.02 is the annual mgmt fee and x is the hourly mgmt fee https://www.wolframalpha.com/input?i=%281-x%29%5E%2824*365%29+%3D+%281-0.02%29
Evaluate expression (e.g. 2% per year --> 2.30624246818947 10^-6)
2.30624246818947*10^-6 => 0.000002306242468
Set the management fee
yarn hardhat --network polygontestnet product:set-product-reference-data-fees --product-name SimpleIndexProduct --management-fee-per-hour 0.000002306242468 --gasprice 5000000000
Guidelines
- Do not deploy to testnet or mainnet from branch
- Bump the version in package.json before PR close
- At closing PR (ideally scipted via actions)
- install with yarn --fixed lock
- Run all tests [yarn dev:test]
- Deploy to testnet [yarn migrate:testnet]
- Add latest JSON to code!!!
- After merging / PR
- Publish new release via github
- Update release version in lib
- Run all the tests in lib
- IF SUCCESSFUL IN LIB, update release verion on relayer
- IF SUCCESSFUL IN LIB, deploy to mainnet
- IF SUCCESSFUL IN LIB, Migrate over funds from old walletFactory address