-
Notifications
You must be signed in to change notification settings - Fork 177
feat(balances): track delegations for Solana #7903
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
adc3beb
feat(balances): track delegations for Solana
limitofzero e967c23
feat(account): add solana approve state(readonly)
limitofzero ba18a7a
chore(i18n): extract i18n strings [automatic]
cowswap-release-sync[bot] 6a3294c
refactor: rename hook + remove comments
limitofzero 3ee5fc2
Merge branch 'feat/sol-delegation-tracking' of github.com:cowprotocol…
limitofzero 090112f
Merge branch 'develop' into feat/sol-delegation-tracking
limitofzero 3486391
fix: reset allowances when an address is being changed
limitofzero 0025e59
Merge branch 'feat/sol-delegation-tracking' of github.com:cowprotocol…
limitofzero 3d07e4f
fix: address review remarks
limitofzero a45f1b3
test: fix units
limitofzero 817aeda
Merge branch 'develop' into feat/sol-delegation-tracking
elena-zh 3e805b0
chore: update bundle sizes [automatic]
cowswap-release-sync[bot] 2b2e9dd
chore: update bundle sizes [automatic]
cowswap-release-sync[bot] 4044e40
chore: update bundle sizes [automatic]
cowswap-release-sync[bot] 4847055
chore: update bundle sizes [automatic]
cowswap-release-sync[bot] 94a71e2
feat: move settlement address to cow-sdk
limitofzero 087d3e0
Merge branch 'develop' into feat/sol-delegation-tracking
limitofzero 473dacd
chore: update bundle sizes [automatic]
cowswap-release-sync[bot] ef969c1
Merge branch 'develop' into feat/sol-delegation-tracking
limitofzero 7f02643
Merge branch 'feat/sol-delegation-tracking' of github.com:cowprotocol…
limitofzero 83e8bbb
chore: update bundle sizes [automatic]
cowswap-release-sync[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
apps/cowswap-frontend/src/legacy/components/Tokens/SplDelegationCell.tsx
This file contains hidden or 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,46 @@ | ||
| import { ReactNode } from 'react' | ||
|
|
||
| import { isFractionFalsy } from '@cowprotocol/common-utils' | ||
| import { CurrencyAmount, Token } from '@cowprotocol/currency' | ||
| import { TokenAmount } from '@cowprotocol/ui' | ||
|
|
||
| import { Trans } from '@lingui/react/macro' | ||
|
|
||
| import { ApproveLabel, NotDelegatedLabel } from './styled' | ||
|
|
||
| type SplDelegationCellProps = { | ||
| balance: CurrencyAmount<Token> | undefined | ||
| allowance: CurrencyAmount<Token> | undefined | ||
| } | ||
|
|
||
| /** | ||
| * Read-only "Actions" cell for Solana rows. Solana has no manual approve flow: the SPL delegation to the | ||
| * CoW settlement authority is fetched read-only (persisted as an allowance), so this mirrors the EVM row's | ||
| * labels without any action button. | ||
| */ | ||
| export function SplDelegationCell({ balance, allowance }: SplDelegationCellProps): ReactNode { | ||
| // No delegation to the CoW settlement authority — neutral placeholder, not a green "approved" state. | ||
| if (isFractionFalsy(allowance)) { | ||
| return <NotDelegatedLabel>—</NotDelegatedLabel> | ||
| } | ||
|
|
||
| // Delegation covers the whole balance → surface it as fully approved, like the EVM row does. | ||
| const fullyDelegated = !!balance && !!allowance && !balance.greaterThan(allowance) | ||
|
|
||
| if (fullyDelegated) { | ||
| return ( | ||
| <ApproveLabel> | ||
| <Trans>Approved</Trans> ✓ | ||
| </ApproveLabel> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <ApproveLabel> | ||
| <Trans>Approved</Trans>:{' '} | ||
| <strong> | ||
| <TokenAmount amount={allowance} /> | ||
| </strong> | ||
| </ApproveLabel> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
libs/balances-and-allowances/src/const/solanaSettlement.ts
This file contains hidden or 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,26 @@ | ||
| import { isBarnBackendEnv } from '@cowprotocol/common-utils' | ||
|
|
||
| import { PublicKey } from '@solana/web3.js' | ||
|
|
||
| // CoW Protocol settlement program on Solana — https://github.com/cowprotocol/solana-programs | ||
| // Prod vs staging is picked by environment, mirroring how EVM contract addresses are handled | ||
| // (see `COW_PROTOCOL_VAULT_RELAYER_ADDRESS`). Also mirrors the order-flow constant in | ||
| // cowswap-frontend's solanaOrderFlow; consolidate to one source once both land. | ||
| const SOLANA_SETTLEMENT_PROGRAM_ID_PROD = new PublicKey('moosEjJg5mbGRPRU7Vg4AaHZLvbbgknevWR9J1bNgME') | ||
| // TODO: swap in the dedicated staging program id once deployed — same as prod until then. | ||
| const SOLANA_SETTLEMENT_PROGRAM_ID_STAGING = SOLANA_SETTLEMENT_PROGRAM_ID_PROD | ||
|
|
||
| export const SOLANA_SETTLEMENT_PROGRAM_ID = isBarnBackendEnv | ||
| ? SOLANA_SETTLEMENT_PROGRAM_ID_STAGING | ||
| : SOLANA_SETTLEMENT_PROGRAM_ID_PROD | ||
|
|
||
| const SETTLEMENT_SEED = new TextEncoder().encode('settlement') | ||
|
|
||
| /** | ||
| * Settlement state PDA — the SPL delegate a sell-token account is approved to. A token's delegation | ||
| * counts as a CoW approval only when its on-account `delegate` equals this PDA (the program pulls the | ||
| * sell funds through it at execution time). This is the Solana analogue of the EVM vault relayer spender. | ||
| */ | ||
| export function findSolanaSettlementStatePda(): PublicKey { | ||
| return PublicKey.findProgramAddressSync([SETTLEMENT_SEED], SOLANA_SETTLEMENT_PROGRAM_ID)[0] | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.