-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
466012c
commit 3093609
Showing
24 changed files
with
9,135 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,27 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
tests: | ||
name: Unit tests | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
registry-url: https://registry.npmjs.org | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: yarn test |
This file contains 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,4 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
dist |
This file contains 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,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn format & yarn test |
This file contains 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,2 @@ | ||
.github | ||
node_modules |
This file contains 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,7 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 4, | ||
"printWidth": 180, | ||
"semi": true | ||
} |
This file contains 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,10 @@ | ||
[ | ||
{ | ||
"path": "dist/sdk.cjs.production.min.js", | ||
"limit": "10 KB" | ||
}, | ||
{ | ||
"path": "dist/sdk.esm.js", | ||
"limit": "10 KB" | ||
} | ||
] |
This file contains 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 @@ | ||
ignore-scripts true |
This file contains 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
# permit2-sdk | ||
# Permit2 sdk | ||
|
||
[![npm version](https://img.shields.io/npm/v/@real-wagmi/permit2-sdk/latest.svg)](https://www.npmjs.com/package/@real-wagmi/permit2-sdk/v/latest) |
This file contains 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,8 @@ | ||
{ | ||
"preset": "ts-jest", | ||
"testEnvironment": "node", | ||
"transform": { | ||
"^.+\\.ts?$": "ts-jest" | ||
}, | ||
"transformIgnorePatterns": ["<rootDir>/node_modules/"] | ||
} |
This file contains 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,49 @@ | ||
{ | ||
"name": "@real-wagmi/permit2-sdk", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"module": "dist/index.mjs", | ||
"files": [ | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"start": "tsup --watch", | ||
"build": "tsup", | ||
"test": "vitest --run", | ||
"lint": "tsdx lint", | ||
"prepare": "yarn build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why", | ||
"format": "prettier --write \"*/**/*.ts\"" | ||
}, | ||
"author": "Wagmi", | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^9.0.0", | ||
"@types/big.js": "^6.2.0", | ||
"@types/jest": "^29.5.12", | ||
"husky": "^8.0.3", | ||
"size-limit": "^9.0.0", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.6.2", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"repository": "https://github.com/RealWagmi/permit2-sdk.git", | ||
"keywords": [ | ||
"wagmi", | ||
"ethereum" | ||
], | ||
"dependencies": { | ||
"@real-wagmi/sdk": "^1.3.9", | ||
"tiny-invariant": "^1.3.1", | ||
"viem": "^2.7.20", | ||
"vitest": "^1.3.1" | ||
} | ||
} |
This file contains 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,41 @@ | ||
export const permit2Abi = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'address', | ||
name: '', | ||
type: 'address', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: '', | ||
type: 'address', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: '', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'allowance', | ||
outputs: [ | ||
{ | ||
internalType: 'uint160', | ||
name: 'amount', | ||
type: 'uint160', | ||
}, | ||
{ | ||
internalType: 'uint48', | ||
name: 'expiration', | ||
type: 'uint48', | ||
}, | ||
{ | ||
internalType: 'uint48', | ||
name: 'nonce', | ||
type: 'uint48', | ||
}, | ||
], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
] as const; |
This file contains 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,142 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { AllowanceTransfer } from './allowanceTransfer'; | ||
import { MaxAllowanceExpiration, MaxAllowanceTransferAmount, MaxOrderedNonce, MaxSigDeadline } from './constants'; | ||
|
||
describe('AllowanceTransfer', () => { | ||
describe('Max values', () => { | ||
it('max values pass', () => { | ||
expect(() => | ||
AllowanceTransfer.hash( | ||
{ | ||
details: { | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: MaxAllowanceTransferAmount.toString(), | ||
expiration: MaxAllowanceExpiration.toString(), | ||
nonce: MaxOrderedNonce.toString(), | ||
}, | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: MaxSigDeadline.toString(), | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('nonce out of range', () => { | ||
expect(() => | ||
AllowanceTransfer.hash( | ||
{ | ||
details: { | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: '0', | ||
expiration: '0', | ||
nonce: MaxOrderedNonce + 1n, | ||
}, | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: '0', | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).toThrow('NONCE_OUT_OF_RANGE'); | ||
}); | ||
|
||
it('amount out of range', () => { | ||
expect(() => | ||
AllowanceTransfer.hash( | ||
{ | ||
details: { | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: MaxAllowanceTransferAmount + 1n, | ||
expiration: '0', | ||
nonce: 0, | ||
}, | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: '0', | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).toThrow('AMOUNT_OUT_OF_RANGE'); | ||
}); | ||
|
||
it('expiration out of range', () => { | ||
expect(() => | ||
AllowanceTransfer.hash( | ||
{ | ||
details: { | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: '0', | ||
expiration: MaxAllowanceExpiration + 1n, | ||
nonce: 0, | ||
}, | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: '0', | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).toThrow('EXPIRATION_OUT_OF_RANGE'); | ||
}); | ||
|
||
it('sigDeadline out of range', () => { | ||
expect(() => | ||
AllowanceTransfer.hash( | ||
{ | ||
details: { | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: '0', | ||
expiration: '0', | ||
nonce: 0, | ||
}, | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: MaxSigDeadline + 1n, | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).toThrow('SIG_DEADLINE_OUT_OF_RANGE'); | ||
}); | ||
}); | ||
|
||
it('non-batch', () => { | ||
expect( | ||
AllowanceTransfer.hash( | ||
{ | ||
details: { | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: '0', | ||
expiration: '0', | ||
nonce: 0, | ||
}, | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: '0', | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).toBe('0xd47437bffdbc4d123a2165feb6ca646b8700c038622ce304f84e9048bc744f36'); | ||
}); | ||
|
||
it('batch', () => { | ||
expect( | ||
AllowanceTransfer.hash( | ||
{ | ||
details: [ | ||
{ | ||
token: '0x0000000000000000000000000000000000000000', | ||
amount: '0', | ||
expiration: '0', | ||
nonce: 0, | ||
}, | ||
], | ||
spender: '0x0000000000000000000000000000000000000000', | ||
sigDeadline: '0', | ||
}, | ||
'0x0000000000000000000000000000000000000000', | ||
1, | ||
), | ||
).toBe('0x49642ada5f77eb9458f8265eb01fed2684c2f25d50534fea3efdf2cf395deb2f'); | ||
}); | ||
}); |
Oops, something went wrong.