This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): update the sdk to detect permit from config
- Loading branch information
1 parent
7e84f74
commit 3715c38
Showing
7 changed files
with
154 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
36 changes: 36 additions & 0 deletions
36
packages/extension/src/client/services/MetaMaskService/permitSchema.js
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,36 @@ | ||
import { signer } from 'aztec.js'; | ||
import utils from '@aztec/dev-utils'; | ||
|
||
const { | ||
constants: { | ||
eip712, | ||
}, | ||
} = utils; | ||
|
||
|
||
export default ({ | ||
spender, | ||
verifyingContract, | ||
allowed, | ||
expiry, | ||
spender, | ||
nonce | ||
}) => { | ||
const domain = signer.generateDAIDomainparams(chainId, verifyingContract); | ||
const schema = eip712.PERMIT_SIGNATURE; | ||
|
||
const message = { | ||
allowed, | ||
spender, | ||
expiry, | ||
nonce, | ||
}; | ||
|
||
const data = JSON.stringify({ | ||
...schema, | ||
message, | ||
domain, | ||
}); | ||
|
||
return data; | ||
}; |
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,3 @@ | ||
export default { | ||
'0x6b175474e89094c44da98b954eedeac495271d0f': true, | ||
}; |
54 changes: 54 additions & 0 deletions
54
packages/extension/src/ui/apis/asset/permitERC20Allowance.js
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,54 @@ | ||
import ConnectionService from '~/ui/services/ConnectionService'; | ||
import Web3Service from '~/helpers/Web3Service'; | ||
|
||
export default async function permitERC20({ | ||
asset, | ||
requestedAllowance, | ||
allowanceSpender, | ||
}) { | ||
|
||
|
||
const { | ||
linkedTokenAddress, | ||
} = asset; | ||
|
||
let error; | ||
try { | ||
const nonce = await Web3Service | ||
.useContract('ERC20') | ||
.at(linkedTokenAddress) | ||
.method('nonces') | ||
.send( | ||
allowanceSpender, | ||
); | ||
} catch (e) { | ||
error = e; | ||
} | ||
const exipry = Date.now() + 24 * 60 * 60; | ||
const { | ||
signature, | ||
error, | ||
} = await ConnectionService.post({ | ||
action: 'metamask.eip712.permit', | ||
data: { | ||
nonce, | ||
expiry, | ||
allowed: requestedAllowance | ||
spender: allowanceSpender, | ||
}, | ||
}); | ||
|
||
if (error) { | ||
return { | ||
error, | ||
}; | ||
} | ||
|
||
return { | ||
spender: sender, | ||
nonce, | ||
expiry, | ||
allowed; requestedAllowance, | ||
signature, | ||
}; | ||
} |
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
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
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