forked from 0xsequence/sequence.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Codesandbox #258
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
Codesandbox #258
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6ecbe48
0xsequence 1.9.19 (#253)
Dargon789 4a6ac5d
Vercel/react server components CVE vu qan1bu (#256)
Dargon789 64367c9
Potential fix for code scanning alert no. 83: Workflow does not conta…
Dargon789 785b063
Potential fix for code scanning alert no. 82: Workflow does not conta…
Dargon789 106b140
extras docs
Dargon789 b44a924
Merge branch 'codesandbox' into v3
Dargon789 966d0ec
Update publish-dists.yml
Dargon789 048f214
Merge pull request #257 from Dargon789/v3
Dargon789 7eb0e62
Merge branch 'master' into codesandbox
Dargon789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
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 @@ | ||
| # Use the latest 2.1 version of CircleCI pipeline process engine. | ||
| # See: https://circleci.com/docs/configuration-reference | ||
|
|
||
| version: 2.1 | ||
| executors: | ||
| my-custom-executor: | ||
| docker: | ||
| - image: cimg/base:stable | ||
| auth: | ||
| # ensure you have first added these secrets | ||
| # visit app.circleci.com/settings/project/github/Dargon789/foundry/environment-variables | ||
| username: $DOCKER_HUB_USER | ||
| password: $DOCKER_HUB_PASSWORD | ||
| jobs: | ||
| web3-defi-game-project-: | ||
|
|
||
| executor: my-custom-executor | ||
| steps: | ||
| - checkout | ||
| - run: | | ||
| # echo Hello, World! | ||
| workflows: | ||
| my-custom-workflow: | ||
| jobs: | ||
| - web3-defi-game-project- | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| /// <reference path="./.next/types/routes.d.ts" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
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,6 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| /// <reference path="./.next/types/routes.d.ts" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
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,190 @@ | ||
| import { Address } from 'ox' | ||
| import { | ||
| Precondition, | ||
| NativeBalancePrecondition, | ||
| Erc20BalancePrecondition, | ||
| Erc20ApprovalPrecondition, | ||
| Erc721OwnershipPrecondition, | ||
| Erc721ApprovalPrecondition, | ||
| Erc1155BalancePrecondition, | ||
| Erc1155ApprovalPrecondition, | ||
| } from './types.js' | ||
|
|
||
| export interface TransactionPrecondition { | ||
| type: string | ||
| chainId: number | ||
| ownerAddress: string | ||
| tokenAddress: string | ||
| minAmount: bigint | ||
| } | ||
|
|
||
| export function decodePreconditions(preconditions: TransactionPrecondition[]): Precondition[] { | ||
| const decodedPreconditions: Precondition[] = [] | ||
|
|
||
| for (const p of preconditions) { | ||
| const decoded = decodePrecondition(p) | ||
| if (decoded) { | ||
| decodedPreconditions.push(decoded) | ||
| } | ||
| } | ||
|
|
||
| return decodedPreconditions | ||
| } | ||
|
|
||
| export function decodePrecondition(p: TransactionPrecondition): Precondition | undefined { | ||
| if (!p) { | ||
| return undefined | ||
| } | ||
|
|
||
| let precondition: Precondition | undefined | ||
|
|
||
| try { | ||
| switch (p.type) { | ||
| case 'native-balance': | ||
| precondition = new NativeBalancePrecondition(Address.from(p.ownerAddress), p.minAmount, undefined) | ||
| break | ||
|
|
||
| case 'erc20-balance': | ||
| precondition = new Erc20BalancePrecondition( | ||
| Address.from(p.ownerAddress), | ||
| Address.from(p.tokenAddress), | ||
| p.minAmount, | ||
| undefined, | ||
| ) | ||
| break | ||
|
|
||
| case 'erc20-approval': | ||
| precondition = new Erc20ApprovalPrecondition( | ||
| Address.from(p.ownerAddress), | ||
| Address.from(p.tokenAddress), | ||
| Address.from(p.ownerAddress), | ||
| p.minAmount, | ||
| ) | ||
| break | ||
|
|
||
| case 'erc721-ownership': | ||
| precondition = new Erc721OwnershipPrecondition( | ||
| Address.from(p.ownerAddress), | ||
| Address.from(p.tokenAddress), | ||
| BigInt(0), | ||
| true, | ||
| ) | ||
| break | ||
|
|
||
| case 'erc721-approval': | ||
| precondition = new Erc721ApprovalPrecondition( | ||
| Address.from(p.ownerAddress), | ||
| Address.from(p.tokenAddress), | ||
| BigInt(0), | ||
| Address.from(p.ownerAddress), | ||
| ) | ||
| break | ||
|
|
||
| case 'erc1155-balance': | ||
| precondition = new Erc1155BalancePrecondition( | ||
| Address.from(p.ownerAddress), | ||
| Address.from(p.tokenAddress), | ||
| BigInt(0), | ||
| p.minAmount, | ||
| undefined, | ||
| ) | ||
| break | ||
|
|
||
| case 'erc1155-approval': | ||
| precondition = new Erc1155ApprovalPrecondition( | ||
| Address.from(p.ownerAddress), | ||
| Address.from(p.tokenAddress), | ||
| BigInt(0), | ||
| Address.from(p.ownerAddress), | ||
| p.minAmount, | ||
| ) | ||
| break | ||
|
|
||
| default: | ||
| return undefined | ||
| } | ||
|
|
||
| const error = precondition.isValid() | ||
| if (error) { | ||
| console.warn(`Invalid precondition: ${error.message}`) | ||
| return undefined | ||
| } | ||
|
|
||
| return precondition | ||
| } catch (e) { | ||
| console.warn(`Failed to decode precondition: ${e}`) | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| export function encodePrecondition(p: Precondition): string { | ||
| const data: any = {} | ||
|
|
||
| switch (p.type()) { | ||
| case 'native-balance': { | ||
| const native = p as NativeBalancePrecondition | ||
| data.address = native.address.toString() | ||
| if (native.min !== undefined) data.min = native.min.toString() | ||
| if (native.max !== undefined) data.max = native.max.toString() | ||
| break | ||
| } | ||
|
|
||
| case 'erc20-balance': { | ||
| const erc20 = p as Erc20BalancePrecondition | ||
| data.address = erc20.address.toString() | ||
| data.token = erc20.token.toString() | ||
| if (erc20.min !== undefined) data.min = erc20.min.toString() | ||
| if (erc20.max !== undefined) data.max = erc20.max.toString() | ||
| break | ||
| } | ||
|
|
||
| case 'erc20-approval': { | ||
| const erc20 = p as Erc20ApprovalPrecondition | ||
| data.address = erc20.address.toString() | ||
| data.token = erc20.token.toString() | ||
| data.operator = erc20.operator.toString() | ||
| data.min = erc20.min.toString() | ||
| break | ||
| } | ||
|
|
||
| case 'erc721-ownership': { | ||
| const erc721 = p as Erc721OwnershipPrecondition | ||
| data.address = erc721.address.toString() | ||
| data.token = erc721.token.toString() | ||
| data.tokenId = erc721.tokenId.toString() | ||
| if (erc721.owned !== undefined) data.owned = erc721.owned | ||
| break | ||
| } | ||
|
|
||
| case 'erc721-approval': { | ||
| const erc721 = p as Erc721ApprovalPrecondition | ||
| data.address = erc721.address.toString() | ||
| data.token = erc721.token.toString() | ||
| data.tokenId = erc721.tokenId.toString() | ||
| data.operator = erc721.operator.toString() | ||
| break | ||
| } | ||
|
|
||
| case 'erc1155-balance': { | ||
| const erc1155 = p as Erc1155BalancePrecondition | ||
| data.address = erc1155.address.toString() | ||
| data.token = erc1155.token.toString() | ||
| data.tokenId = erc1155.tokenId.toString() | ||
| if (erc1155.min !== undefined) data.min = erc1155.min.toString() | ||
| if (erc1155.max !== undefined) data.max = erc1155.max.toString() | ||
| break | ||
| } | ||
|
|
||
| case 'erc1155-approval': { | ||
| const erc1155 = p as Erc1155ApprovalPrecondition | ||
| data.address = erc1155.address.toString() | ||
| data.token = erc1155.token.toString() | ||
| data.tokenId = erc1155.tokenId.toString() | ||
| data.operator = erc1155.operator.toString() | ||
| data.min = erc1155.min.toString() | ||
| break | ||
| } | ||
| } | ||
|
|
||
| return JSON.stringify(data) | ||
| } |
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,3 @@ | ||
| export * from './types.js' | ||
| export * from './codec.js' | ||
| export * from './selectors.js' |
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,38 @@ | ||
| import { Precondition, NativeBalancePrecondition, Erc20BalancePrecondition } from './types.js' | ||
| import { TransactionPrecondition, decodePreconditions } from './codec.js' | ||
|
|
||
| export function extractChainID(precondition: TransactionPrecondition): number | undefined { | ||
| if (!precondition) { | ||
| return undefined | ||
| } | ||
|
|
||
| return precondition.chainId | ||
| } | ||
|
|
||
| export function extractSupportedPreconditions(preconditions: TransactionPrecondition[]): Precondition[] { | ||
| if (!preconditions || preconditions.length === 0) { | ||
| return [] | ||
| } | ||
|
|
||
| return decodePreconditions(preconditions) | ||
| } | ||
|
|
||
| export function extractNativeBalancePreconditions( | ||
| preconditions: TransactionPrecondition[], | ||
| ): NativeBalancePrecondition[] { | ||
| if (!preconditions || preconditions.length === 0) { | ||
| return [] | ||
| } | ||
|
|
||
| const decoded = decodePreconditions(preconditions) | ||
| return decoded.filter((p): p is NativeBalancePrecondition => p.type() === 'native-balance') | ||
| } | ||
|
|
||
| export function extractERC20BalancePreconditions(preconditions: TransactionPrecondition[]): Erc20BalancePrecondition[] { | ||
| if (!preconditions || preconditions.length === 0) { | ||
| return [] | ||
| } | ||
|
|
||
| const decoded = decodePreconditions(preconditions) | ||
| return decoded.filter((p): p is Erc20BalancePrecondition => p.type() === 'erc20-balance') | ||
| } |
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.