@exponent-labs/adrena-idl 0.1.7 → 0.9.0
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/build/index.d.ts +6 -3
- package/build/index.js +21 -21
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +19 -23
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { IdlAccounts, IdlTypes, web3 } from "@coral-xyz/anchor";
|
|
3
|
+
import { BorshCoder, IdlAccounts, IdlTypes, web3 } from "@coral-xyz/anchor";
|
|
4
4
|
import BN from "bn.js";
|
|
5
5
|
import { Adrena } from "./adrena";
|
|
6
6
|
type AdrenaAccounts = IdlAccounts<Adrena>;
|
|
@@ -8,9 +8,12 @@ type AdrenaTypes = IdlTypes<Adrena>;
|
|
|
8
8
|
export type PoolState = AdrenaAccounts["pool"];
|
|
9
9
|
export type CustodyState = AdrenaAccounts["custody"];
|
|
10
10
|
export type FeesStats = AdrenaTypes["FeesStats"];
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const ADRENA_CODER: BorshCoder<string, string>;
|
|
12
|
+
export declare const fetchPoolAccount: (connection: web3.Connection, accountPubkey: web3.PublicKey) => Promise<PoolState>;
|
|
13
|
+
export declare const decodePoolAccount: (data: Buffer) => any;
|
|
12
14
|
export declare const encodePoolAccount: (accountBuffer: any) => Promise<Buffer>;
|
|
13
|
-
export declare const
|
|
15
|
+
export declare const fetchCustodyAccount: (connection: web3.Connection, accountPubkey: web3.PublicKey) => Promise<CustodyState>;
|
|
16
|
+
export declare const decodeCustodyAccount: (data: Buffer) => any;
|
|
14
17
|
export declare const encodeCustodyAccount: (custody: any) => Promise<Buffer>;
|
|
15
18
|
export declare const decodePoolAndCustodyAccounts: (accountInfos: {
|
|
16
19
|
data: Buffer;
|
package/build/index.js
CHANGED
|
@@ -3,51 +3,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calculateTotalFeesFromCustodies = exports.decodePoolAndCustodyAccounts = exports.encodeCustodyAccount = exports.decodeCustodyAccount = exports.encodePoolAccount = exports.decodePoolAccount = void 0;
|
|
6
|
+
exports.calculateTotalFeesFromCustodies = exports.decodePoolAndCustodyAccounts = exports.encodeCustodyAccount = exports.decodeCustodyAccount = exports.fetchCustodyAccount = exports.encodePoolAccount = exports.decodePoolAccount = exports.fetchPoolAccount = exports.ADRENA_CODER = void 0;
|
|
7
7
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
8
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
9
|
const adrena_json_1 = __importDefault(require("./adrena.json")); // <-- the raw IDL
|
|
10
10
|
const ADRENA_POOL_IDL = adrena_json_1.default;
|
|
11
|
-
|
|
11
|
+
exports.ADRENA_CODER = new anchor_1.BorshCoder(ADRENA_POOL_IDL);
|
|
12
|
+
const fetchPoolAccount = async (connection, accountPubkey) => {
|
|
12
13
|
const account = await connection.getAccountInfo(accountPubkey);
|
|
13
14
|
if (!account) {
|
|
14
15
|
throw new Error(`Could not fetch Adrena Pool ${accountPubkey.toString()}`);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return (0, exports.decodePoolAccount)(account.data);
|
|
18
|
+
};
|
|
19
|
+
exports.fetchPoolAccount = fetchPoolAccount;
|
|
20
|
+
const decodePoolAccount = (data) => {
|
|
21
|
+
return exports.ADRENA_CODER.accounts.decode("Pool", data);
|
|
19
22
|
};
|
|
20
23
|
exports.decodePoolAccount = decodePoolAccount;
|
|
21
24
|
const encodePoolAccount = async (accountBuffer) => {
|
|
22
|
-
|
|
23
|
-
return coder.accounts.encode("Pool", accountBuffer);
|
|
25
|
+
return exports.ADRENA_CODER.accounts.encode("Pool", accountBuffer);
|
|
24
26
|
};
|
|
25
27
|
exports.encodePoolAccount = encodePoolAccount;
|
|
26
|
-
const
|
|
28
|
+
const fetchCustodyAccount = async (connection, accountPubkey) => {
|
|
27
29
|
const account = await connection.getAccountInfo(accountPubkey);
|
|
28
30
|
if (!account) {
|
|
29
31
|
throw new Error(`Could not fetch Adrena Custody ${accountPubkey.toString()}`);
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
return (0, exports.decodeCustodyAccount)(account.data);
|
|
34
|
+
};
|
|
35
|
+
exports.fetchCustodyAccount = fetchCustodyAccount;
|
|
36
|
+
const decodeCustodyAccount = (data) => {
|
|
37
|
+
return exports.ADRENA_CODER.accounts.decode("Custody", data);
|
|
34
38
|
};
|
|
35
39
|
exports.decodeCustodyAccount = decodeCustodyAccount;
|
|
36
40
|
const encodeCustodyAccount = async (custody) => {
|
|
37
|
-
|
|
38
|
-
return coder.accounts.encode("Custody", custody);
|
|
41
|
+
return exports.ADRENA_CODER.accounts.encode("Custody", custody);
|
|
39
42
|
};
|
|
40
43
|
exports.encodeCustodyAccount = encodeCustodyAccount;
|
|
41
44
|
// Decode pool and custody accounts from raw account data (without additional RPC calls)
|
|
42
45
|
const decodePoolAndCustodyAccounts = (accountInfos) => {
|
|
43
|
-
const
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
const poolAccount = coder.accounts.decode("Pool", accountInfos[0].data);
|
|
46
|
+
const poolAccount = exports.ADRENA_CODER.accounts.decode("Pool", accountInfos[0].data);
|
|
46
47
|
const custodyAccounts = [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
exports.ADRENA_CODER.accounts.decode("Custody", accountInfos[1].data),
|
|
49
|
+
exports.ADRENA_CODER.accounts.decode("Custody", accountInfos[2].data),
|
|
50
|
+
exports.ADRENA_CODER.accounts.decode("Custody", accountInfos[3].data),
|
|
51
|
+
exports.ADRENA_CODER.accounts.decode("Custody", accountInfos[4].data),
|
|
51
52
|
];
|
|
52
53
|
return { poolAccount, custodyAccounts };
|
|
53
54
|
};
|
|
@@ -56,7 +57,6 @@ exports.decodePoolAndCustodyAccounts = decodePoolAndCustodyAccounts;
|
|
|
56
57
|
const calculateTotalFeesFromCustodies = (custodyAccounts) => {
|
|
57
58
|
return custodyAccounts.reduce((acc, c) => {
|
|
58
59
|
const fees = c.collectedFees;
|
|
59
|
-
// @ts-ignore
|
|
60
60
|
const totalCustodyFees = fees.swapUsd
|
|
61
61
|
.add(fees.addLiquidityUsd)
|
|
62
62
|
.add(fees.removeLiquidityUsd)
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAgF;AAChF,kDAAsB;AAGtB,gEAAsC,CAAC,kBAAkB;AAEzD,MAAM,eAAe,GAAQ,qBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAgF;AAChF,kDAAsB;AAGtB,gEAAsC,CAAC,kBAAkB;AAEzD,MAAM,eAAe,GAAQ,qBAAiB,CAAA;AAYjC,QAAA,YAAY,GAAG,IAAI,mBAAU,CAAC,eAAe,CAAC,CAAA;AAEpD,MAAM,gBAAgB,GAAG,KAAK,EACnC,UAA2B,EAC3B,aAA6B,EAET,EAAE;IACtB,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,aAAa,CAAC,CAAA;IAE9D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+BAA+B,aAAa,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,OAAO,IAAA,yBAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AACxC,CAAC,CAAA;AAZY,QAAA,gBAAgB,oBAY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
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,7 +16,9 @@ export type PoolState = AdrenaAccounts["pool"]
|
|
|
16
16
|
export type CustodyState = AdrenaAccounts["custody"]
|
|
17
17
|
export type FeesStats = AdrenaTypes["FeesStats"]
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const ADRENA_CODER = new BorshCoder(ADRENA_POOL_IDL)
|
|
20
|
+
|
|
21
|
+
export const fetchPoolAccount = async (
|
|
20
22
|
connection: web3.Connection,
|
|
21
23
|
accountPubkey: web3.PublicKey,
|
|
22
24
|
// @ts-ignore
|
|
@@ -27,19 +29,18 @@ export const decodePoolAccount = async (
|
|
|
27
29
|
throw new Error(`Could not fetch Adrena Pool ${accountPubkey.toString()}`)
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
return decodePoolAccount(account.data)
|
|
33
|
+
}
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
return
|
|
35
|
+
export const decodePoolAccount = (data: Buffer): PoolState => {
|
|
36
|
+
return ADRENA_CODER.accounts.decode<PoolState>("Pool", data)
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
export const encodePoolAccount = async (accountBuffer: PoolState) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return coder.accounts.encode("Pool", accountBuffer)
|
|
40
|
+
return ADRENA_CODER.accounts.encode("Pool", accountBuffer)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export const
|
|
43
|
+
export const fetchCustodyAccount = async (
|
|
43
44
|
connection: web3.Connection,
|
|
44
45
|
accountPubkey: web3.PublicKey,
|
|
45
46
|
): Promise<CustodyState> => {
|
|
@@ -49,29 +50,25 @@ export const decodeCustodyAccount = async (
|
|
|
49
50
|
throw new Error(`Could not fetch Adrena Custody ${accountPubkey.toString()}`)
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
return decodeCustodyAccount(account.data)
|
|
54
|
+
}
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
+
export const decodeCustodyAccount = (data: Buffer): CustodyState => {
|
|
57
|
+
return ADRENA_CODER.accounts.decode<CustodyState>("Custody", data)
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
export const encodeCustodyAccount = async (custody: CustodyState) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return coder.accounts.encode("Custody", custody)
|
|
61
|
+
return ADRENA_CODER.accounts.encode("Custody", custody)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// Decode pool and custody accounts from raw account data (without additional RPC calls)
|
|
65
65
|
export const decodePoolAndCustodyAccounts = (accountInfos: { data: Buffer }[]) => {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
const poolAccount = coder.accounts.decode("Pool", accountInfos[0].data) as PoolState
|
|
66
|
+
const poolAccount = ADRENA_CODER.accounts.decode("Pool", accountInfos[0].data) as PoolState
|
|
70
67
|
const custodyAccounts = [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
ADRENA_CODER.accounts.decode("Custody", accountInfos[1].data) as CustodyState,
|
|
69
|
+
ADRENA_CODER.accounts.decode("Custody", accountInfos[2].data) as CustodyState,
|
|
70
|
+
ADRENA_CODER.accounts.decode("Custody", accountInfos[3].data) as CustodyState,
|
|
71
|
+
ADRENA_CODER.accounts.decode("Custody", accountInfos[4].data) as CustodyState,
|
|
75
72
|
]
|
|
76
73
|
|
|
77
74
|
return { poolAccount, custodyAccounts }
|
|
@@ -82,7 +79,6 @@ export const calculateTotalFeesFromCustodies = (custodyAccounts: CustodyState[])
|
|
|
82
79
|
return custodyAccounts.reduce((acc: BN, c: CustodyState) => {
|
|
83
80
|
const fees = c.collectedFees as FeesStats
|
|
84
81
|
|
|
85
|
-
// @ts-ignore
|
|
86
82
|
const totalCustodyFees = fees.swapUsd
|
|
87
83
|
.add(fees.addLiquidityUsd)
|
|
88
84
|
.add(fees.removeLiquidityUsd)
|