Skip to content

Commit

Permalink
Remove outdated eth-permit in favor of custom code
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Sep 16, 2024
1 parent e8a66c1 commit 42ebed4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
1 change: 0 additions & 1 deletion centrifuge-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@stablelib/blake2b": "^1.0.1",
"clp-wasm": "^0.0.15",
"decimal.js-light": "^2.5.1",
"eth-permit": "^0.2.3",
"isomorphic-fetch": "^3.0.0",
"jw3t": "^1.0.8",
"lodash": "^4.17.21"
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-js/src/modules/liquidityPools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import BN from 'bn.js'
import { signERC2612Permit } from 'eth-permit'
import type { TransactionRequest, TransactionResponse } from 'ethers'
import { Contract, Interface, Provider, ethers } from 'ethers'
import set from 'lodash/set'
Expand All @@ -8,6 +7,7 @@ import { Centrifuge } from '../Centrifuge'
import { TransactionOptions } from '../types'
import { CurrencyBalance, TokenBalance } from '../utils/BN'
import { Call, multicall } from '../utils/evmMulticall'
import { signERC2612Permit } from '../utils/signERC2612Permit'
import * as ABI from './liquidityPools/abi'
import { CurrencyKey, CurrencyMetadata, getCurrencyEvmAddress, getCurrencyLocation } from './pools'

Expand Down
2 changes: 0 additions & 2 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3801,8 +3801,6 @@ export function getPoolsModule(inst: Centrifuge) {
switchMap(({ api, pool: rawPool }) => {
const pool = rawPool.toHuman() as PoolDetailsData
const trancheIds = pool.tranches.ids
console.log('🚀 ~ trancheIds:', trancheIds)
console.log('🚀 ~ poolId:', poolId)
return combineLatest([
api.queryMulti(
trancheIds.flatMap((trancheId) => [
Expand Down
67 changes: 67 additions & 0 deletions centrifuge-js/src/utils/signERC2612Permit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ethers } from 'ethers'

export async function signERC2612Permit(
provider: any,
token: string | { name: string; version: string; chainId: number; verifyingContract: string },
owner: string,
spender: string,
value: string,
deadline: number
) {
const tokenAddress = typeof token === 'string' ? token : token.verifyingContract
const tokenContract = new ethers.Contract(
tokenAddress,
['function name() view returns (string)', 'function nonces(address) view returns (uint256)'],
provider
)

let name: string, version: string, chainId: number
if (typeof token === 'string') {
name = await tokenContract.name()
version = '1'
chainId = Number((await provider.getNetwork()).chainId)
} else {
;({ name, version, chainId } = token)
}

const domain = {
name,
version,
chainId,
verifyingContract: tokenAddress,
}

const types = {
Permit: [
{ name: 'owner', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'deadline', type: 'uint256' },
],
}

const nonce = await tokenContract.nonces(owner)

const values = {
owner,
spender,
value,
nonce,
deadline,
}

const signer = await provider.getSigner(owner)
const signature = await signer.signTypedData(domain, types, values)
const { v, r, s } = ethers.Signature.from(signature)

return {
owner,
spender,
value,
deadline,
v,
r,
s,
}
}
12 changes: 1 addition & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,6 @@ __metadata:
clp-wasm: ^0.0.15
decimal.js-light: ^2.5.1
eslint: ^7.32.0
eth-permit: ^0.2.3
isomorphic-fetch: ^3.0.0
jest: ^27.4.3
jw3t: ^1.0.8
Expand Down Expand Up @@ -16092,15 +16091,6 @@ __metadata:
languageName: node
linkType: hard

"eth-permit@npm:^0.2.3":
version: 0.2.3
resolution: "eth-permit@npm:0.2.3"
dependencies:
utf8: ^3.0.0
checksum: 9bf3eed8ecb8c914aadfff97d6c3d19fc432928c72fbe205075153e84289ea95f3a101f77e2dae78ad629e09682700241f207b5436b575ca7d4fbae68eacd3f6
languageName: node
linkType: hard

"eth-query@npm:^2.1.2":
version: 2.1.2
resolution: "eth-query@npm:2.1.2"
Expand Down Expand Up @@ -27340,7 +27330,7 @@ __metadata:
languageName: node
linkType: hard

"utf8@npm:3.0.0, utf8@npm:^3.0.0":
"utf8@npm:3.0.0":
version: 3.0.0
resolution: "utf8@npm:3.0.0"
checksum: cb89a69ad9ab393e3eae9b25305b3ff08bebca9adc839191a34f90777eb2942f86a96369d2839925fea58f8f722f7e27031d697f10f5f39690f8c5047303e62d
Expand Down

0 comments on commit 42ebed4

Please sign in to comment.