@velocity-exchange/vaults-sdk 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accountSubscribers/index.d.ts +3 -0
- package/lib/accountSubscribers/index.d.ts.map +1 -0
- package/lib/accountSubscribers/index.js +18 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.d.ts +8 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.d.ts.map +1 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.js +46 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.d.ts +8 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.d.ts.map +1 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.js +46 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.d.ts +28 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.d.ts.map +1 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.js +71 -0
- package/lib/accounts/index.d.ts +3 -0
- package/lib/accounts/index.d.ts.map +1 -0
- package/lib/accounts/index.js +18 -0
- package/lib/accounts/vaultAccount.d.ts +27 -0
- package/lib/accounts/vaultAccount.d.ts.map +1 -0
- package/lib/accounts/vaultAccount.js +174 -0
- package/lib/accounts/vaultDepositorAccount.d.ts +18 -0
- package/lib/accounts/vaultDepositorAccount.d.ts.map +1 -0
- package/lib/accounts/vaultDepositorAccount.js +47 -0
- package/lib/accounts/vaultsProgramAccount.d.ts +13 -0
- package/lib/accounts/vaultsProgramAccount.d.ts.map +1 -0
- package/lib/accounts/vaultsProgramAccount.js +25 -0
- package/lib/addresses.d.ts +10 -0
- package/lib/addresses.d.ts.map +1 -0
- package/lib/addresses.js +87 -0
- package/lib/constants/index.d.ts +8 -0
- package/lib/constants/index.d.ts.map +1 -0
- package/lib/constants/index.js +12 -0
- package/lib/idl/drift_vaults.json +5698 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +27 -0
- package/lib/math/index.d.ts +3 -0
- package/lib/math/index.d.ts.map +1 -0
- package/lib/math/index.js +18 -0
- package/lib/math/vault.d.ts +17 -0
- package/lib/math/vault.d.ts.map +1 -0
- package/lib/math/vault.js +56 -0
- package/lib/math/vaultDepositor.d.ts +24 -0
- package/lib/math/vaultDepositor.d.ts.map +1 -0
- package/lib/math/vaultDepositor.js +49 -0
- package/lib/name.d.ts +4 -0
- package/lib/name.d.ts.map +1 -0
- package/lib/name.js +19 -0
- package/lib/parsers/index.d.ts +2 -0
- package/lib/parsers/index.d.ts.map +1 -0
- package/lib/parsers/index.js +17 -0
- package/lib/parsers/logParser.d.ts +15 -0
- package/lib/parsers/logParser.d.ts.map +1 -0
- package/lib/parsers/logParser.js +21 -0
- package/lib/types/drift_vaults.d.ts +6212 -0
- package/lib/types/drift_vaults.d.ts.map +1 -0
- package/lib/types/drift_vaults.js +2 -0
- package/lib/types/types.d.ts +283 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +48 -0
- package/lib/utils.d.ts +10 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +69 -0
- package/lib/vaultClient.d.ts +446 -0
- package/lib/vaultClient.d.ts.map +1 -0
- package/lib/vaultClient.js +1914 -0
- package/package.json +1 -1
- package/velocity-exchange-vaults-sdk-0.0.1.tgz +0 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './addresses';
|
|
2
|
+
export * from './name';
|
|
3
|
+
export * from './vaultClient';
|
|
4
|
+
export * from './accounts';
|
|
5
|
+
export * from './accountSubscribers';
|
|
6
|
+
export * from './utils';
|
|
7
|
+
export * from './types/types';
|
|
8
|
+
export * from './constants';
|
|
9
|
+
export * from './parsers';
|
|
10
|
+
export * from './types/drift_vaults';
|
|
11
|
+
export * from './math';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./addresses"), exports);
|
|
18
|
+
__exportStar(require("./name"), exports);
|
|
19
|
+
__exportStar(require("./vaultClient"), exports);
|
|
20
|
+
__exportStar(require("./accounts"), exports);
|
|
21
|
+
__exportStar(require("./accountSubscribers"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
23
|
+
__exportStar(require("./types/types"), exports);
|
|
24
|
+
__exportStar(require("./constants"), exports);
|
|
25
|
+
__exportStar(require("./parsers"), exports);
|
|
26
|
+
__exportStar(require("./types/drift_vaults"), exports);
|
|
27
|
+
__exportStar(require("./math"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/math/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vaultDepositor"), exports);
|
|
18
|
+
__exportStar(require("./vault"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BN, BigNum } from '@velocity-exchange/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* https://en.wikipedia.org/wiki/Modified_Dietz_method
|
|
4
|
+
* @param currentVaultEquityBaseValue
|
|
5
|
+
* @param vaultDeposits
|
|
6
|
+
* @returns weighted APY and cumulative returns calculated using the Modified Dietz method
|
|
7
|
+
*/
|
|
8
|
+
export declare const calcModifiedDietz: (currentVaultEquityBaseValue: BigNum, precisionExp: BN, vaultDeposits: {
|
|
9
|
+
ts: string;
|
|
10
|
+
marketIndex: number;
|
|
11
|
+
amount: string;
|
|
12
|
+
direction: "deposit" | "withdraw";
|
|
13
|
+
}[], startingMarketValue?: number) => {
|
|
14
|
+
apy: number;
|
|
15
|
+
returns: number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=vault.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../src/math/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAOpD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,gCACA,MAAM,gBACrB,EAAE,iBACD;IACd,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;CAClC,EAAE,mCAED;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CA+ChC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcModifiedDietz = void 0;
|
|
4
|
+
const sdk_1 = require("@velocity-exchange/sdk");
|
|
5
|
+
const DEFAULT_MODIFIED_DIETZ_RESULT = {
|
|
6
|
+
apy: 0,
|
|
7
|
+
returns: 0,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* https://en.wikipedia.org/wiki/Modified_Dietz_method
|
|
11
|
+
* @param currentVaultEquityBaseValue
|
|
12
|
+
* @param vaultDeposits
|
|
13
|
+
* @returns weighted APY and cumulative returns calculated using the Modified Dietz method
|
|
14
|
+
*/
|
|
15
|
+
const calcModifiedDietz = (currentVaultEquityBaseValue, precisionExp, vaultDeposits, startingMarketValue = 0) => {
|
|
16
|
+
if (vaultDeposits.length === 0) {
|
|
17
|
+
return DEFAULT_MODIFIED_DIETZ_RESULT;
|
|
18
|
+
}
|
|
19
|
+
const endingMarkeValue = currentVaultEquityBaseValue.toNum();
|
|
20
|
+
const firstDepositTs = parseInt(vaultDeposits[vaultDeposits.length - 1].ts);
|
|
21
|
+
const lastDepositTs = parseInt(vaultDeposits[0].ts);
|
|
22
|
+
const nowTs = Date.now() / 1000;
|
|
23
|
+
if (nowTs < firstDepositTs) {
|
|
24
|
+
console.error('nowTs < firstDepositTs');
|
|
25
|
+
return DEFAULT_MODIFIED_DIETZ_RESULT;
|
|
26
|
+
}
|
|
27
|
+
if (lastDepositTs < firstDepositTs) {
|
|
28
|
+
console.error('lastDepositTs < firstDepositTs');
|
|
29
|
+
return DEFAULT_MODIFIED_DIETZ_RESULT;
|
|
30
|
+
}
|
|
31
|
+
const totalDuration = nowTs - firstDepositTs;
|
|
32
|
+
let totalNetFlow = 0;
|
|
33
|
+
let weightedNetFlow = 0;
|
|
34
|
+
vaultDeposits.forEach((deposit) => {
|
|
35
|
+
let depositAmount = sdk_1.BigNum.from(deposit.amount, precisionExp).toNum();
|
|
36
|
+
if (deposit.direction === 'withdraw') {
|
|
37
|
+
depositAmount *= -1;
|
|
38
|
+
}
|
|
39
|
+
totalNetFlow += depositAmount;
|
|
40
|
+
const depositAge = parseInt(deposit.ts) - firstDepositTs;
|
|
41
|
+
const depositWeight = (totalDuration - depositAge) / totalDuration;
|
|
42
|
+
if (depositWeight < 0) {
|
|
43
|
+
console.error('depositWeight < 0');
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
weightedNetFlow += depositWeight * depositAmount;
|
|
47
|
+
}, 0);
|
|
48
|
+
const modifiedDietzReturns = (endingMarkeValue - startingMarketValue - totalNetFlow) /
|
|
49
|
+
(startingMarketValue + weightedNetFlow);
|
|
50
|
+
if (modifiedDietzReturns < 0)
|
|
51
|
+
return DEFAULT_MODIFIED_DIETZ_RESULT;
|
|
52
|
+
const annualized = Math.pow(1 + modifiedDietzReturns, (86400 * 365) / totalDuration) - 1;
|
|
53
|
+
const positiveApy = Math.max(annualized, 0);
|
|
54
|
+
return { apy: positiveApy, returns: modifiedDietzReturns };
|
|
55
|
+
};
|
|
56
|
+
exports.calcModifiedDietz = calcModifiedDietz;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BN } from '@velocity-exchange/sdk';
|
|
2
|
+
import { Vault, VaultDepositor, VaultProtocol } from '../types/types';
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the unrealized profitShare for a vaultDepositor
|
|
5
|
+
* @param vaultDepositor
|
|
6
|
+
* @param vaultEquity
|
|
7
|
+
* @param vault
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function calculateApplyProfitShare(vaultDepositor: VaultDepositor, vaultEquity: BN, vault: Vault): {
|
|
11
|
+
profitShareAmount: BN;
|
|
12
|
+
profitShareShares: BN;
|
|
13
|
+
};
|
|
14
|
+
export declare function calculateProfitShare(vaultDepositor: VaultDepositor, totalAmount: BN, vault: Vault, vaultProtocol?: VaultProtocol): BN;
|
|
15
|
+
/**
|
|
16
|
+
* Calculates the equity across deposits and realized profit for a vaultDepositor
|
|
17
|
+
* @param vaultDepositor vault depositor account
|
|
18
|
+
* @param vaultEquity total vault equity
|
|
19
|
+
* @param vault vault account
|
|
20
|
+
* @param vaultProtocol if vault account has "vaultProtocol" then this is needed
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function calculateRealizedVaultDepositorEquity(vaultDepositor: VaultDepositor, vaultEquity: BN, vault: Vault, vaultProtocol?: VaultProtocol): BN;
|
|
24
|
+
//# sourceMappingURL=vaultDepositor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vaultDepositor.d.ts","sourceRoot":"","sources":["../../src/math/vaultDepositor.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,EAAE,EAKF,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACxC,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,EAAE,EACf,KAAK,EAAE,KAAK,GACV;IACF,iBAAiB,EAAE,EAAE,CAAC;IACtB,iBAAiB,EAAE,EAAE,CAAC;CACtB,CAgBA;AAED,wBAAgB,oBAAoB,CACnC,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,EAAE,EACf,KAAK,EAAE,KAAK,EACZ,aAAa,CAAC,EAAE,aAAa,MAgB7B;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACpD,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,EAAE,EACf,KAAK,EAAE,KAAK,EACZ,aAAa,CAAC,EAAE,aAAa,GAC3B,EAAE,CAaJ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateApplyProfitShare = calculateApplyProfitShare;
|
|
4
|
+
exports.calculateProfitShare = calculateProfitShare;
|
|
5
|
+
exports.calculateRealizedVaultDepositorEquity = calculateRealizedVaultDepositorEquity;
|
|
6
|
+
const sdk_1 = require("@velocity-exchange/sdk");
|
|
7
|
+
/**
|
|
8
|
+
* Calculates the unrealized profitShare for a vaultDepositor
|
|
9
|
+
* @param vaultDepositor
|
|
10
|
+
* @param vaultEquity
|
|
11
|
+
* @param vault
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function calculateApplyProfitShare(vaultDepositor, vaultEquity, vault) {
|
|
15
|
+
const amount = (0, sdk_1.unstakeSharesToAmount)(vaultDepositor.vaultShares, vault.totalShares, vaultEquity);
|
|
16
|
+
const profitShareAmount = calculateProfitShare(vaultDepositor, amount, vault);
|
|
17
|
+
const profitShareShares = (0, sdk_1.stakeAmountToShares)(profitShareAmount, vault.totalShares, vaultEquity);
|
|
18
|
+
return {
|
|
19
|
+
profitShareAmount,
|
|
20
|
+
profitShareShares,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function calculateProfitShare(vaultDepositor, totalAmount, vault, vaultProtocol) {
|
|
24
|
+
const profit = totalAmount.sub(vaultDepositor.netDeposits.add(vaultDepositor.cumulativeProfitShareAmount));
|
|
25
|
+
let profitShare = vault.profitShare;
|
|
26
|
+
if (vaultProtocol) {
|
|
27
|
+
profitShare += vaultProtocol.protocolProfitShare;
|
|
28
|
+
}
|
|
29
|
+
if (profit.gt(sdk_1.ZERO)) {
|
|
30
|
+
const profitShareAmount = profit
|
|
31
|
+
.mul(new sdk_1.BN(profitShare))
|
|
32
|
+
.div(sdk_1.PERCENTAGE_PRECISION);
|
|
33
|
+
return profitShareAmount;
|
|
34
|
+
}
|
|
35
|
+
return sdk_1.ZERO;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calculates the equity across deposits and realized profit for a vaultDepositor
|
|
39
|
+
* @param vaultDepositor vault depositor account
|
|
40
|
+
* @param vaultEquity total vault equity
|
|
41
|
+
* @param vault vault account
|
|
42
|
+
* @param vaultProtocol if vault account has "vaultProtocol" then this is needed
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
function calculateRealizedVaultDepositorEquity(vaultDepositor, vaultEquity, vault, vaultProtocol) {
|
|
46
|
+
const vdAmount = (0, sdk_1.unstakeSharesToAmount)(vaultDepositor.vaultShares, vault.totalShares, vaultEquity);
|
|
47
|
+
const profitShareAmount = calculateProfitShare(vaultDepositor, vdAmount, vault, vaultProtocol);
|
|
48
|
+
return vdAmount.sub(profitShareAmount);
|
|
49
|
+
}
|
package/lib/name.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../src/name.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAUjD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAGlD"}
|
package/lib/name.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_NAME_LENGTH = void 0;
|
|
4
|
+
exports.encodeName = encodeName;
|
|
5
|
+
exports.decodeName = decodeName;
|
|
6
|
+
exports.MAX_NAME_LENGTH = 32;
|
|
7
|
+
function encodeName(name) {
|
|
8
|
+
if (name.length > exports.MAX_NAME_LENGTH) {
|
|
9
|
+
throw Error(`Name (${name}) longer than 32 characters`);
|
|
10
|
+
}
|
|
11
|
+
const buffer = Buffer.alloc(32);
|
|
12
|
+
buffer.fill(name);
|
|
13
|
+
buffer.fill(' ', name.length);
|
|
14
|
+
return Array(...buffer);
|
|
15
|
+
}
|
|
16
|
+
function decodeName(bytes) {
|
|
17
|
+
const buffer = Buffer.from(bytes);
|
|
18
|
+
return buffer.toString('utf8').trim();
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parsers/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logParser"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Program } from '@coral-xyz/anchor';
|
|
2
|
+
import { TransactionSignature } from '@solana/web3.js';
|
|
3
|
+
import { WrappedEvents } from '../types/types';
|
|
4
|
+
type Log = {
|
|
5
|
+
txSig: TransactionSignature;
|
|
6
|
+
slot: number;
|
|
7
|
+
logs: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare class LogParser {
|
|
10
|
+
private program;
|
|
11
|
+
constructor(program: Program);
|
|
12
|
+
parseEventsFromLogs(event: Log): WrappedEvents;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=logParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logParser.d.ts","sourceRoot":"","sources":["../../src/parsers/logParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,KAAK,GAAG,GAAG;IAAE,KAAK,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEzE,qBAAa,SAAS;IACT,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO;IAE7B,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,aAAa;CAkBrD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogParser = void 0;
|
|
4
|
+
class LogParser {
|
|
5
|
+
constructor(program) {
|
|
6
|
+
this.program = program;
|
|
7
|
+
}
|
|
8
|
+
parseEventsFromLogs(event) {
|
|
9
|
+
const records = [];
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const eventGenerator = this.program._events._eventParser.parseLogs(event.logs, false);
|
|
12
|
+
for (const eventLog of eventGenerator) {
|
|
13
|
+
eventLog.data.txSig = event.txSig;
|
|
14
|
+
eventLog.data.slot = event.slot;
|
|
15
|
+
eventLog.data.eventType = eventLog.name;
|
|
16
|
+
records.push(eventLog.data);
|
|
17
|
+
}
|
|
18
|
+
return records;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.LogParser = LogParser;
|