Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Tulipe wrapper for all Ethers.js contract classes
- Loading branch information
0Lilian
committed
Sep 4, 2022
1 parent
76d85f9
commit d60bf57
Showing
1 changed file
with
42 additions
and
0 deletions.
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,42 @@ | ||
import { | ||
Contract, | ||
ERC20Contract | ||
} from "ethers"; | ||
|
||
import { TulipeContractProxy } from "../../index.js"; | ||
|
||
export class TulipeContract extends Contract { | ||
constructor (...args) { | ||
|
||
// Determine proxy class | ||
let proxyClass = TulipeContractProxy; | ||
if (args[args.length - 1].prototype instanceof TulipeContractProxy) { // Last argument can be a proxy class | ||
proxyClass = args.pop(); | ||
} | ||
|
||
// Initialize parent constructor. | ||
super(...args) | ||
|
||
// Build and return proxy. | ||
const proxy = new proxyClass(this) | ||
return proxy | ||
} | ||
} | ||
|
||
export class TulipeERC20Contract extends ERC20Contract { | ||
constructor (...args) { | ||
|
||
// Determine proxy class | ||
let proxyClass = TulipeContractProxy; | ||
if (args[args.length - 1].prototype instanceof TulipeContractProxy) { // Last argument can be a proxy class | ||
proxyClass = args.pop(); | ||
} | ||
|
||
// Initialize parent constructor. | ||
super(...args) | ||
|
||
// Build and return proxy. | ||
const proxy = new proxyClass(this) | ||
return proxy | ||
} | ||
} |