Skip to content

feat: referral farms#6128

Merged
guanbinrui merged 153 commits into
DimensionDev:developfrom
attrace:feat/plugin-referral-farms
Jun 4, 2022
Merged

feat: referral farms#6128
guanbinrui merged 153 commits into
DimensionDev:developfrom
attrace:feat/plugin-referral-farms

Conversation

@mariiaSynoverska

@mariiaSynoverska mariiaSynoverska commented Apr 22, 2022

Copy link
Copy Markdown
Contributor

Description

First version of Referral Farms plugin:

Screenshot 2022-04-22 at 11 24 50

Flows that should be tested:

  1. Create Farm | Crypto Tokens
    1.1 Increase/decrease the Daily Farm Reward.
    1.2 Deposit Additional Farm Rewards.
Create_Farm.mov
  1. Refer to Farm, Option 1: Referral Farms => Crypto Tokens => Refer to Farm
Refer_to_Farm_Option_1.mov
  1. Refer to Farm, Option 2: Tweet created by Publish Farm => Refer to Farm
Refer_to_Farm_Option_2.mov
  1. Buy to Farm, Option 1: Referral Farms => Crypto Tokens => Buy to Farm
Buy_to_Farm_Option_1.mov
  1. Buy to Farm, Option 2: Tweet created by Promoter => Buy to Farm
Buy_to_Farm_Option_2.mov

E2E flow:

  1. Create Farm by Sponsor account
  2. Refer to Farm by Promoter account
  3. Buy to Farm by Participant account.
  4. Buy Referred token on Uniswap Rinkeby: As far as, Trader(Swap) plugin doesn’t support Rinkeby, you should use Uniswap Rinkeby to buy Referred token.
    Important: Don't use ETH to buy your ERC20 Referred token, use swap from ERC20 token to your ERC20 Referred token.
Buy_WETH.mov
  1. Check Promoter and Participant rewards: Oracle should pick your position and you will see rewards in the Refer to Farm | My farms and Buy to Farm | My farms.
    Note: TESTNET Oracle updates reward every 2 hours. So, you will see your rewards in the My farms tab 2 hours after "Buy Referred token on DEX".
My_farms.mov

The changes outside of Referral Farms plugin:

Small fix in packages/mask/src/plugins/Trader/SNSAdaptor/trader/TraderDialog.tsx to support traderProps.chainId

 - <Trader {...traderProps} chainId={chainId} classes={{ root: classes.tradeRoot }} />
 + <Trader chainId={chainId} {...traderProps} classes={{ root: classes.tradeRoot }} />

Comment thread packages/mask/src/plugins/Referral/base.ts Outdated
@guanbinrui guanbinrui changed the title Feat/plugin referral farms feat: referral farms Apr 24, 2022
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/BuyToFarm.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/BuyToFarm.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/BuyToFarm.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/BuyToFarm.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/BuyToFarm.tsx Outdated
Comment thread packages/plugins/Flow/src/base.ts Outdated
Comment thread packages/mask/src/plugins/Trader/SNSAdaptor/trader/TraderDialog.tsx
Comment thread packages/mask/src/plugins/Referral/types.ts
Comment thread packages/mask/src/plugins/Referral/types.ts Outdated
Comment thread packages/mask/src/plugins/Referral/types.ts Outdated
mariiaSynoverska and others added 2 commits June 3, 2022 10:32
Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com>
Comment thread packages/mask/src/plugins/Referral/helpers/index.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/Worker/apis/entitlements.ts Outdated
Comment thread packages/mask/src/plugins/Referral/Worker/apis/discovery.ts
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/AdjustFarmRewards.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/BuyToFarm.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/CreateFarm.tsx Outdated
variant="contained"
size="medium"
className={classes.buttonWithdraw}
onClick={() => console.log('request to withdraw')}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hasn't it been implemented yet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this button is disabled now, we decided to postpone withdrawal feature to the next release.

mariiaSynoverska and others added 5 commits June 3, 2022 10:48
Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com>
…s.tsx

Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com>
Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com>
Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com>
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/CreatedFarms.tsx Outdated
Comment thread packages/mask/src/plugins/Referral/SNSAdaptor/FarmPost.tsx Outdated
if (typeof b === 'number') return BigInt(b)
if (b instanceof Uint8Array) return toBigInt(buf(b))
if (typeof b === 'string' && b.startsWith('0x')) return BigInt(b)
if (b instanceof BigNumber || (b as any)?._isBigNumber === true) return BigInt(b as any)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (b instanceof BigNumber || (b as any)?._isBigNumber === true) return BigInt(b as any)
if (b instanceof BigNumber || (b as any)?._isBigNumber === true) return BigInt(b as BigNumber)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

import { bufToHexString, toBigInt, writeUInt32BE, hexToArrayBuffer } from './buffer'

function toChainAddress(chainId: BigNumber | bigint, address: Uint8Array): Uint8Array {
if (isValidAddress(address.toString())) throw new Error('invalid address')

@guanbinrui guanbinrui Jun 3, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isValidAddress(address.toString())) throw new Error('invalid address')
if (isValidAddress(bufToHexString(address))) throw new Error('invalid address')

FYI: The Web3 utils lib has https://web3js.readthedocs.io/en/v1.7.3/web3-utils.html#bytestohex.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytesToHex(bytes: number[]): string, address here is address: Uint8Array.
TS error: Argument of type 'Uint8Array' is not assignable to parameter of type 'number[]'.

Probably do you know some utils to convert Uint8Array to string?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can expand to an array of numbers. I noticed that the 0x should add as a prefix.

`0x${bufToHexString(...address)}`

@mariiaSynoverska mariiaSynoverska Jun 3, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks, done refactoring and use bytestohex

@mariiaSynoverska

Copy link
Copy Markdown
Contributor Author

@guanbinrui, thanks for all your suggestions, I resolved all of them.
Could you check please when you have a moment? If you don’t see anything new, I think we are ready to merge.

@guanbinrui

Copy link
Copy Markdown
Member

@guanbinrui, thanks for all your suggestions, I resolved all of them. Could you check please when you have a moment? If you don’t see anything new, I think we are ready to merge.

Thanks! I will merge it.

@guanbinrui
guanbinrui merged commit 7d5543d into DimensionDev:develop Jun 4, 2022
etouyang added a commit to etouyang/Maskbook that referenced this pull request Jun 7, 2022
* 'develop' of github.com:etouyang/Maskbook: (173 commits)
  feat: more debugger connection actions (DimensionDev#6438)
  fix: sign tx by wallet with mnemonic words (DimensionDev#6437)
  fix: sign arbitrary message (DimensionDev#6436)
  fix: bugfix for refactor (DimensionDev#6434)
  fix: lost overrides (DimensionDev#6435)
  feat: add useAccountName (DimensionDev#6429)
  fix: button logic under EVM chain (DimensionDev#6431)
  fix: gas price fallback (DimensionDev#6432)
  chore: update node-version for workspace (DimensionDev#6428)
  refactor: social address list (DimensionDev#6410)
  fix: bugfix for trader (DimensionDev#6424)
  fix: duplicated db fetch (DimensionDev#6426)
  docs(i18n): sync i18n files from Crowdin (DimensionDev#6425)
  fix: tsc need restart to handle new file or removed file in watch mode
  fix: lint errors
  feat: referral farms (DimensionDev#6128)
  fix: fixup maskbox for evm migrate (DimensionDev#6395)
  fix: pets artblocks plugin (DimensionDev#6393)
  docs: update compat table
  refactor: add RecentTransactionComputed (DimensionDev#6420)
  ...

# Conflicts:
#	packages/dashboard/src/initialization/isolated_bridge.ts
#	packages/mask/src/extension/dashboard/index.tsx
#	packages/mask/src/plugins/Pets/SNSAdaptor/PetSetDialog.tsx
#	packages/mask/src/plugins/Pets/SNSAdaptor/PreviewBox.tsx
#	packages/mask/src/plugins/Pets/Services/rss3.ts
#	packages/mask/src/plugins/Pets/hooks/useNfts.ts
#	packages/shared/src/index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants