@hemergy/core-sdk
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -14,2 +14,3 @@ import { AxiosInstance } from 'axios'; | ||
getMeta(): Promise<Meta>; | ||
private signAndBroadcast; | ||
getContracts(): Promise<{ | ||
@@ -20,5 +21,10 @@ accountsFactoryContract: ethers.Contract; | ||
getSignerAddress(): Promise<string>; | ||
approveAccountAmount(accountAddress: string, projectAddress: string, tokenAddress: string, amount: number): Promise<void>; | ||
createAccount(): Promise<string>; | ||
createProject(accountAddress: string, beneficiaries?: string[]): Promise<string>; | ||
addProjectBeneficiaries(projectAddress: string, beneficiaryAddress: string): Promise<void>; | ||
investInProject(projectAddress: string, investorAccountAddress: string, amount: number): Promise<void>; | ||
divestInProject(projectAddress: string, investorAccountAddress: string, amount: number): Promise<void>; | ||
mint(address: string): Promise<number>; | ||
isKYCed(accountAddress: string): Promise<boolean>; | ||
} |
@@ -32,2 +32,10 @@ "use strict"; | ||
} | ||
signAndBroadcast(url, payload) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data: { request, domain, ForwardRequest }, } = yield this.axiosClient.post(url, payload); | ||
const signature = yield this.signer._signTypedData(domain, { ForwardRequest }, request); | ||
const { data } = yield this.axiosClient.post('/relayer', { signature, request }); | ||
return data; | ||
}); | ||
} | ||
getContracts() { | ||
@@ -50,2 +58,14 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
approveAccountAmount(accountAddress, projectAddress, tokenAddress, amount) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const signerAddress = yield this.getSignerAddress(); | ||
yield this.signAndBroadcast(`/accounts/${accountAddress}/approve`, { | ||
endUserAddress: signerAddress, | ||
accountAddress, | ||
tokenAddress, | ||
projectAddress, | ||
amount, | ||
}); | ||
}); | ||
} | ||
createAccount() { | ||
@@ -57,5 +77,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
]); | ||
const { data: { request, domain, ForwardRequest }, } = yield this.axiosClient.post('/accounts', { endUserAddress: signerAddress }); | ||
const signature = yield this.signer._signTypedData(domain, { ForwardRequest }, request); | ||
const { data: { logs }, } = yield this.axiosClient.post('/relayer', { signature, request }); | ||
const { logs } = yield this.signAndBroadcast('/accounts', { endUserAddress: signerAddress }); | ||
const accountEvent = accountsFactoryContract.interface.parseLog(logs[0]); | ||
@@ -72,3 +90,3 @@ const accountAddress = accountEvent.args.account; | ||
]); | ||
const { data: { request, domain, ForwardRequest }, } = yield this.axiosClient.post('/projects', { | ||
const { logs } = yield this.signAndBroadcast('/projects', { | ||
endUserAddress: signerAddress, | ||
@@ -78,4 +96,2 @@ projectHolder: accountAddress, | ||
}); | ||
const signature = yield this.signer._signTypedData(domain, { ForwardRequest }, request); | ||
const { data: { logs }, } = yield this.axiosClient.post('/relayer', { signature, request }); | ||
const projectEvent = projectsFactoryContract.interface.parseLog(logs[0]); | ||
@@ -86,2 +102,40 @@ const projectAddress = projectEvent.args.project; | ||
} | ||
addProjectBeneficiaries(projectAddress, beneficiaryAddress) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const signerAddress = yield this.getContracts(); | ||
yield this.signAndBroadcast(`/projects/${projectAddress}/beneficiaries`, { | ||
endUserAddress: signerAddress, | ||
projectAddress, | ||
beneficiaryAddress, | ||
}); | ||
}); | ||
} | ||
investInProject(projectAddress, investorAccountAddress, amount) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const signerAddress = yield this.getContracts(); | ||
yield this.signAndBroadcast(`/projects/${projectAddress}/invest`, { | ||
endUserAddress: signerAddress, | ||
projectAddress, | ||
investorAccountAddress, | ||
amount, | ||
}); | ||
}); | ||
} | ||
divestInProject(projectAddress, investorAccountAddress, amount) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const signerAddress = yield this.getContracts(); | ||
yield this.signAndBroadcast(`/projects/${projectAddress}/divest`, { | ||
endUserAddress: signerAddress, | ||
projectAddress, | ||
investorAccountAddress, | ||
amount, | ||
}); | ||
}); | ||
} | ||
mint(address) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.axiosClient.post('bank/mint', { address }); | ||
return data; | ||
}); | ||
} | ||
isKYCed(accountAddress) { | ||
@@ -88,0 +142,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@hemergy/core-sdk", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "TypeScript NPM Module for Hemergy Core", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
10989
204