Skip to content

Commit

Permalink
feat(managers): adds new managers and getFactory static method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexangelj committed Jan 5, 2022
1 parent 5c1223f commit e50a7ec
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 19 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@primitivefi/rmm-sdk",
"version": "1.0.4-beta.4",
"description": "A Software Development Kit for Primitive RMM-01",
"description": "A Software Development Kit for Primitive RMM-01.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"license": "GPL-3.0-or-later",
Expand Down Expand Up @@ -29,8 +29,8 @@
"docs:api-documenter": "api-documenter generate -i temp/sdk-api -o docs/sdk"
},
"dependencies": {
"@primitivefi/rmm-core": "^2.0.0-beta.1",
"@primitivefi/rmm-manager": "^2.0.0-beta.2",
"@primitivefi/rmm-core": "^2.0.0-beta.5",
"@primitivefi/rmm-manager": "^2.0.0-beta.5",
"@primitivefi/rmm-math": "^2.0.0-beta.2",
"@uniswap/sdk-core": "^3.0.1",
"tiny-invariant": "^1.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/factoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import invariant from 'tiny-invariant'
import { getAddress } from 'ethers/lib/utils'
import { Interface } from '@ethersproject/abi'
import { AddressZero } from '@ethersproject/constants'
import { Signer } from '@ethersproject/abstract-signer'
import { ContractFactory } from '@ethersproject/contracts'

import FactoryArtifact from '@primitivefi/rmm-core/artifacts/contracts/PrimitiveFactory.sol/PrimitiveFactory.json'

Expand All @@ -13,7 +15,9 @@ import FactoryArtifact from '@primitivefi/rmm-core/artifacts/contracts/Primitive
export abstract class FactoryManager {
public static INTERFACE: Interface = new Interface(FactoryArtifact.abi)
public static BYTECODE: string = FactoryArtifact.bytecode
public static ABI: any = FactoryArtifact.abi
public static ABI: any[] = FactoryArtifact.abi
public static getFactory: (signer?: Signer) => ContractFactory = signer =>
new ContractFactory(FactoryManager.INTERFACE, FactoryManager.BYTECODE, signer)

private constructor() {}

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './entities'
export * from './factoryManager'
export * from './positionDescriptorManager'
export * from './positionRendererManager'
export * from './peripheryManager'
export * from './selfPermit'
export * from './swapManager'
Expand Down
6 changes: 5 additions & 1 deletion src/peripheryManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Interface } from '@ethersproject/abi'
import { BigNumber } from '@ethersproject/bignumber'
import { AddressZero } from '@ethersproject/constants'
import { Signer } from '@ethersproject/abstract-signer'
import { ContractFactory } from '@ethersproject/contracts'
import invariant from 'tiny-invariant'
import { parseWei, Percentage, toBN, Wei } from 'web3-units'
import { NativeCurrency } from '@uniswap/sdk-core'
Expand Down Expand Up @@ -91,7 +93,9 @@ export interface BatchTransferOptions {
export abstract class PeripheryManager extends SelfPermit {
public static INTERFACE: Interface = new Interface(ManagerArtifact.abi)
public static BYTECODE: string = ManagerArtifact.bytecode
public static ABI: any = ManagerArtifact.abi
public static ABI: any[] = ManagerArtifact.abi
public static getFactory: (signer?: Signer) => ContractFactory = signer =>
new ContractFactory(PeripheryManager.INTERFACE, PeripheryManager.BYTECODE, signer)

private constructor() {
super()
Expand Down
20 changes: 20 additions & 0 deletions src/positionDescriptorManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Interface } from '@ethersproject/abi'
import { Signer } from '@ethersproject/abstract-signer'
import { ContractFactory } from '@ethersproject/contracts'

import PositionDescriptorArtifact from '@primitivefi/rmm-manager/artifacts/contracts/PositionDescriptor.sol/PositionDescriptor.json'

/**
* Abstract class for PositionDescriptor.
*
* @beta
*/
export abstract class PositionDescriptorManager {
public static INTERFACE: Interface = new Interface(PositionDescriptorArtifact.abi)
public static BYTECODE: string = PositionDescriptorArtifact.bytecode
public static ABI: any[] = PositionDescriptorArtifact.abi
public static getFactory: (signer?: Signer) => ContractFactory = signer =>
new ContractFactory(PositionDescriptorManager.INTERFACE, PositionDescriptorManager.BYTECODE, signer)

private constructor() {}
}
20 changes: 20 additions & 0 deletions src/positionRendererManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Interface } from '@ethersproject/abi'
import { Signer } from '@ethersproject/abstract-signer'
import { ContractFactory } from '@ethersproject/contracts'

import PositionRendererArtifact from '@primitivefi/rmm-manager/artifacts/contracts/PositionRenderer.sol/PositionRenderer.json'

/**
* Abstract class for PositionRenderer.
*
* @beta
*/
export abstract class PositionRendererManager {
public static INTERFACE: Interface = new Interface(PositionRendererArtifact.abi)
public static BYTECODE: string = PositionRendererArtifact.bytecode
public static ABI: any[] = PositionRendererArtifact.abi
public static getFactory: (signer?: Signer) => ContractFactory = signer =>
new ContractFactory(PositionRendererManager.INTERFACE, PositionRendererManager.BYTECODE, signer)

private constructor() {}
}
6 changes: 5 additions & 1 deletion src/swapManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { BigNumber } from 'ethers'
import invariant from 'tiny-invariant'
import { Interface } from '@ethersproject/abi'
import { Signer } from '@ethersproject/abstract-signer'
import { AddressZero } from '@ethersproject/constants'
import { ContractFactory } from '@ethersproject/contracts'
import { parseWei, Percentage, toBN, Wei } from 'web3-units'
import ManagerArtifact from '@primitivefi/rmm-manager/artifacts/contracts/PrimitiveManager.sol/PrimitiveManager.json'

Expand Down Expand Up @@ -54,7 +56,9 @@ export interface SwapOptions extends DefaultOptions, NativeOptions {
export abstract class SwapManager extends SelfPermit {
public static INTERFACE: Interface = new Interface(ManagerArtifact.abi)
public static BYTECODE: string = ManagerArtifact.bytecode
public static ABI: any = ManagerArtifact.abi
public static ABI: any[] = ManagerArtifact.abi
public static getFactory: (signer?: Signer) => ContractFactory = signer =>
new ContractFactory(SwapManager.INTERFACE, SwapManager.BYTECODE, signer)

private constructor() {
super()
Expand Down
7 changes: 7 additions & 0 deletions test/FactoryManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Token } from '@uniswap/sdk-core'
import { FactoryManager } from '../src/factoryManager'
import { AddressZero } from '@ethersproject/constants'
import { AddressOne, AddressTwo } from './shared'
import { ContractFactory } from 'ethers'

function decode(frag: string, data: any) {
return FactoryManager.INTERFACE.decodeFunctionData(frag, data)
Expand All @@ -15,6 +16,12 @@ describe('FactoryManager', function() {
zeroToken = new Token(1, AddressZero, 18)
})

it('getFactory returns the ethers factory', async function() {
expect(FactoryManager.getFactory()).toStrictEqual(
new ContractFactory(FactoryManager.INTERFACE, FactoryManager.BYTECODE)
)
})

describe('#encodeDeploy', function() {
it('successful', async function() {
const data = [token0.address, token1.address]
Expand Down
8 changes: 7 additions & 1 deletion test/PeripheryManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PeripheryManager } from '../src/peripheryManager'

import { AddressOne } from './shared/constants'
import { usePool, usePoolWithDecimals, useWethPool } from './shared/fixture'
import { BigNumber } from 'ethers'
import { BigNumber, ContractFactory } from 'ethers'

function decode(frag: string, data: any) {
return PeripheryManager.INTERFACE.decodeFunctionData(frag, data)
Expand All @@ -27,6 +27,12 @@ describe('Periphery Manager', function() {
useNative = Ether.onChain(1)
})

it('getFactory returns the ethers factory', async function() {
expect(PeripheryManager.getFactory()).toStrictEqual(
new ContractFactory(PeripheryManager.INTERFACE, PeripheryManager.BYTECODE)
)
})

describe('#encodeCreate', function() {
it('successful', async function() {
const liquidity = parseWei(1, 18)
Expand Down
12 changes: 12 additions & 0 deletions test/PositionDescriptor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PositionDescriptorManager } from '../src/positionDescriptorManager'
import { ContractFactory } from 'ethers'

describe('PositionDescriptorManager', function() {
describe('#getFactory', function() {
it('getFactory returns the ethers factory', async function() {
expect(PositionDescriptorManager.getFactory()).toStrictEqual(
new ContractFactory(PositionDescriptorManager.INTERFACE, PositionDescriptorManager.BYTECODE)
)
})
})
})
12 changes: 12 additions & 0 deletions test/PositionRenderer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PositionRendererManager } from '../src/positionRendererManager'
import { ContractFactory } from 'ethers'

describe('PositionRendererManager', function() {
describe('#getFactory', function() {
it('successful', async function() {
expect(PositionRendererManager.getFactory()).toStrictEqual(
new ContractFactory(PositionRendererManager.INTERFACE, PositionRendererManager.BYTECODE)
)
})
})
})
5 changes: 5 additions & 0 deletions test/SwapManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SwapManager } from '../src/swapManager'

import { usePool } from './shared/fixture'
import { AddressOne } from './shared/constants'
import { ContractFactory } from 'ethers'

function decode(frag: string, data: any) {
return SwapManager.INTERFACE.decodeFunctionData(frag, data)
Expand All @@ -18,6 +19,10 @@ describe('Swap Manager', function() {
pool = usePool()
})

it('getFactory returns the ethers factory', async function() {
expect(SwapManager.getFactory()).toStrictEqual(new ContractFactory(SwapManager.INTERFACE, SwapManager.BYTECODE))
})

describe('#swapCallParameters', function() {
it('successful', async function() {
const riskyForStable = true
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1573,22 +1573,22 @@
integrity sha512-WrHvO8PDL8wd8T2+zBGKrMwVL5IyzR3ryWUsl0PXgEV0QHup4mTLi0QcATefGI6Gx9Anu7vthPyyyLpY0EpiQg==

"@openzeppelin/contracts@^4.1.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.4.0.tgz#4a1df71f736c31230bbbd634dfb006a756b51e6b"
integrity sha512-dlKiZmDvJnGRLHojrDoFZJmsQVeltVeoiRN7RK+cf2FmkhASDEblE0RiaYdxPNsUZa6mRG8393b9bfyp+V5IAw==
version "4.4.1"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.4.1.tgz#3382db2cd83ab565ed9626765e7da92944b45de8"
integrity sha512-o+pHCf/yMLSlV5MkDQEzEQL402i6SoRnktru+0rdSxVEFZcTzzGhZCAtZjUFyKGazMSv1TilzMg+RbED1N8XHQ==

"@primitivefi/rmm-core@^2.0.0-beta.1":
version "2.0.0-beta.1"
resolved "https://registry.yarnpkg.com/@primitivefi/rmm-core/-/rmm-core-2.0.0-beta.1.tgz#de5fb7214dfe15bd59fa6f82fcd27e2372024ee1"
integrity sha512-uZ2znraiDMefzIYBFozs3JMkL6pBloM1fINIc9SwZ4gAPcgT9zM1kwpX2nVdQvPbjBkPaa4XJMavs2wfRpwo1g==
"@primitivefi/rmm-core@2.0.0-beta.5", "@primitivefi/rmm-core@^2.0.0-beta.5":
version "2.0.0-beta.5"
resolved "https://registry.yarnpkg.com/@primitivefi/rmm-core/-/rmm-core-2.0.0-beta.5.tgz#c03426e880f5dff9f8aacd5ffb378f18182f756a"
integrity sha512-fqtN89L4/gxA+M2heUkGlY9/907oJfBwWaWgE5XfhMP5KE+YeE0yKWgo4HNpkx1VPqpoDJU84LmDnCd+8xhVvg==

"@primitivefi/rmm-manager@^2.0.0-beta.2":
version "2.0.0-beta.2"
resolved "https://registry.yarnpkg.com/@primitivefi/rmm-manager/-/rmm-manager-2.0.0-beta.2.tgz#45a493256b2b0629bd1d9136de749c7887b4b628"
integrity sha512-Yz5bPX351fWGRG+hzH3WQd+2aFR3IBPuaS8dPuJr5JDFzgrlMyoOpbkWb4IStBDHiC+RTJlha1Hp88C3SGiUaQ==
"@primitivefi/rmm-manager@^2.0.0-beta.5":
version "2.0.0-beta.5"
resolved "https://registry.yarnpkg.com/@primitivefi/rmm-manager/-/rmm-manager-2.0.0-beta.5.tgz#e71dc3e309b22831bb2e5c858ef0ca8d174f61d5"
integrity sha512-tNXWq8sM89E8zrlF3hVobCkly0jphTyGrzhSoxxpH0TTRIBN05tLCkCGEh/WKcTh20sZw8s2QTTxs9yPoS3gTQ==
dependencies:
"@openzeppelin/contracts" "^4.1.0"
"@primitivefi/rmm-core" "^2.0.0-beta.1"
"@primitivefi/rmm-core" "2.0.0-beta.5"
base64-sol "^1.1.0"

"@primitivefi/rmm-math@^2.0.0-beta.2":
Expand Down

0 comments on commit e50a7ec

Please sign in to comment.