@kamino-finance/klend-sdk 4.0.2 → 4.1.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/README.md +2 -2
- package/dist/classes/action.d.ts +3 -1
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +62 -61
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/obligation.d.ts +9 -0
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +8 -0
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +3 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +32 -0
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +8 -0
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/shared.js +6 -1
- package/dist/classes/shared.js.map +1 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +19 -5
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +18 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +62 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +27 -43
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +99 -152
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +14 -3
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +184 -128
- package/dist/leverage/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +12 -3
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +26 -39
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +18 -0
- package/dist/utils/instruction.js.map +1 -1
- package/package.json +3 -3
- package/src/classes/action.ts +92 -98
- package/src/classes/obligation.ts +15 -6
- package/src/classes/reserve.ts +48 -1
- package/src/classes/shared.ts +10 -0
- package/src/classes/vault.ts +23 -19
- package/src/lending_operations/repay_with_collateral_calcs.ts +98 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +233 -253
- package/src/leverage/operations.ts +227 -140
- package/src/utils/ata.ts +33 -56
- package/src/utils/index.ts +0 -2
- package/src/utils/instruction.ts +22 -0
- package/dist/utils/layout.d.ts +0 -14
- package/dist/utils/layout.d.ts.map +0 -1
- package/dist/utils/layout.js +0 -123
- package/dist/utils/layout.js.map +0 -1
- package/dist/utils/syncNative.d.ts +0 -11
- package/dist/utils/syncNative.d.ts.map +0 -1
- package/dist/utils/syncNative.js +0 -45
- package/dist/utils/syncNative.js.map +0 -1
- package/src/global.d.ts +0 -1
- package/src/utils/layout.ts +0 -118
- package/src/utils/syncNative.ts +0 -22
package/src/utils/ata.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
createAssociatedTokenAccountIdempotentInstruction as createAtaIx,
|
|
5
5
|
} from '@solana/spl-token';
|
|
6
6
|
import { ComputeBudgetProgram, Connection, PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
|
|
7
|
-
import { SOL_MINTS } from '../leverage';
|
|
8
7
|
import Decimal from 'decimal.js';
|
|
9
8
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
10
9
|
|
|
@@ -60,72 +59,50 @@ export function getAssociatedTokenAddress(
|
|
|
60
59
|
export const getAtasWithCreateIxnsIfMissing = async (
|
|
61
60
|
connection: Connection,
|
|
62
61
|
user: PublicKey,
|
|
63
|
-
mints: PublicKey
|
|
64
|
-
|
|
65
|
-
) =>
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
sum = sum.concat(item.closeIxns);
|
|
77
|
-
return sum;
|
|
78
|
-
}, [] as TransactionInstruction[]);
|
|
79
|
-
|
|
62
|
+
mints: Array<{ mint: PublicKey; tokenProgram: PublicKey }>
|
|
63
|
+
): Promise<{ atas: PublicKey[]; createAtaIxs: TransactionInstruction[] }> => {
|
|
64
|
+
const atas: Array<PublicKey> = mints.map((x) => getAssociatedTokenAddress(x.mint, user, true, x.tokenProgram));
|
|
65
|
+
const accountInfos = await connection.getMultipleAccountsInfo(atas);
|
|
66
|
+
const createAtaIxs: TransactionInstruction[] = [];
|
|
67
|
+
for (let i = 0; i < atas.length; i++) {
|
|
68
|
+
if (!accountInfos[i]) {
|
|
69
|
+
const { mint, tokenProgram } = mints[i];
|
|
70
|
+
const [ata, createIxn] = createAssociatedTokenAccountIdempotentInstruction(user, mint, user, tokenProgram);
|
|
71
|
+
atas[i] = ata;
|
|
72
|
+
createAtaIxs.push(createIxn);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
80
75
|
return {
|
|
81
76
|
atas,
|
|
82
|
-
|
|
83
|
-
closeAtasIxns,
|
|
77
|
+
createAtaIxs,
|
|
84
78
|
};
|
|
85
79
|
};
|
|
86
80
|
|
|
87
|
-
|
|
88
|
-
connection: Connection,
|
|
81
|
+
export function createAtasIdempotent(
|
|
89
82
|
user: PublicKey,
|
|
90
|
-
mint: PublicKey
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
83
|
+
mints: Array<{ mint: PublicKey; tokenProgram: PublicKey }>
|
|
84
|
+
): Array<{ ata: PublicKey; createAtaIx: TransactionInstruction }> {
|
|
85
|
+
const res: Array<{ ata: PublicKey; createAtaIx: TransactionInstruction }> = [];
|
|
86
|
+
for (const mint of mints) {
|
|
87
|
+
const [ata, createAtaIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
88
|
+
user,
|
|
89
|
+
mint.mint,
|
|
90
|
+
user,
|
|
91
|
+
mint.tokenProgram
|
|
92
|
+
);
|
|
93
|
+
res.push({
|
|
94
|
+
ata,
|
|
95
|
+
createAtaIx,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return res;
|
|
99
|
+
}
|
|
105
100
|
|
|
106
101
|
export const checkIfAccountExists = async (connection: Connection, account: PublicKey): Promise<boolean> => {
|
|
107
102
|
const acc = await connection.getAccountInfo(account);
|
|
108
103
|
return acc !== null;
|
|
109
104
|
};
|
|
110
105
|
|
|
111
|
-
const getAtaByTokenMint = async (
|
|
112
|
-
connection: Connection,
|
|
113
|
-
user: PublicKey,
|
|
114
|
-
tokenMint: PublicKey,
|
|
115
|
-
tokenProgram: PublicKey = TOKEN_PROGRAM_ID
|
|
116
|
-
): Promise<PublicKey | null> => {
|
|
117
|
-
if (tokenMint.equals(SOL_MINTS[0])) {
|
|
118
|
-
return user;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const ataAddress = getAssociatedTokenAddress(tokenMint, user, true, tokenProgram);
|
|
122
|
-
if (await checkIfAccountExists(connection, ataAddress)) {
|
|
123
|
-
return ataAddress;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return null;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
106
|
export function getDepositWsolIxns(owner: PublicKey, ata: PublicKey, amountLamports: Decimal) {
|
|
130
107
|
const ixns: TransactionInstruction[] = [];
|
|
131
108
|
|
|
@@ -183,7 +160,7 @@ export async function getTokenAccountBalanceDecimal(
|
|
|
183
160
|
mint: PublicKey,
|
|
184
161
|
owner: PublicKey
|
|
185
162
|
): Promise<Decimal> {
|
|
186
|
-
const tokenAta =
|
|
163
|
+
const tokenAta = getAssociatedTokenAddress(mint, owner);
|
|
187
164
|
const ataExists = await checkIfAccountExists(connection, tokenAta);
|
|
188
165
|
|
|
189
166
|
if (!ataExists) {
|
package/src/utils/index.ts
CHANGED
|
@@ -3,11 +3,9 @@ export * from './ata';
|
|
|
3
3
|
export * from './constants';
|
|
4
4
|
export * from './idl';
|
|
5
5
|
export * from './instruction';
|
|
6
|
-
export * from './layout';
|
|
7
6
|
export * from './ObligationType';
|
|
8
7
|
export * from './seeds';
|
|
9
8
|
export * from './slots';
|
|
10
|
-
export * from './syncNative';
|
|
11
9
|
export * from './userMetadata';
|
|
12
10
|
export * from './pubkey';
|
|
13
11
|
export * from './oracle';
|
package/src/utils/instruction.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import { fromTxError } from '../idl_codegen/errors';
|
|
21
21
|
import { sleep } from '../classes/utils';
|
|
22
22
|
import { batchFetch } from '@kamino-finance/kliquidity-sdk';
|
|
23
|
+
import { PublicKeySet } from './pubkey';
|
|
23
24
|
|
|
24
25
|
export async function buildAndSendTxnWithLogs(
|
|
25
26
|
c: Connection,
|
|
@@ -256,3 +257,24 @@ export function notEmpty<TValue>(value: TValue | null | undefined): value is TVa
|
|
|
256
257
|
const testDummy: TValue = value;
|
|
257
258
|
return true;
|
|
258
259
|
}
|
|
260
|
+
|
|
261
|
+
export function uniqueAccounts(
|
|
262
|
+
ixs: TransactionInstruction[],
|
|
263
|
+
addressLookupTables: PublicKey[] | AddressLookupTableAccount[] = []
|
|
264
|
+
): Array<PublicKey> {
|
|
265
|
+
let luts: PublicKey[];
|
|
266
|
+
if (addressLookupTables.length > 0 && addressLookupTables[0] instanceof AddressLookupTableAccount) {
|
|
267
|
+
luts = (addressLookupTables as AddressLookupTableAccount[]).map((lut) => lut.key);
|
|
268
|
+
} else {
|
|
269
|
+
luts = addressLookupTables as PublicKey[];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const uniqueAccounts = new PublicKeySet<PublicKey>(luts);
|
|
273
|
+
ixs.forEach((ixn) => {
|
|
274
|
+
ixn.keys.forEach((key) => {
|
|
275
|
+
uniqueAccounts.add(key.pubkey);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return uniqueAccounts.toArray();
|
|
280
|
+
}
|
package/dist/utils/layout.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Layout for a public key
|
|
3
|
-
*/
|
|
4
|
-
export declare const publicKey: (property?: string) => unknown;
|
|
5
|
-
/**
|
|
6
|
-
* Layout for a 64bit unsigned value
|
|
7
|
-
*/
|
|
8
|
-
export declare const uint64: (property?: string) => unknown;
|
|
9
|
-
export declare const uint128: (property?: string) => unknown;
|
|
10
|
-
/**
|
|
11
|
-
* Layout for a Rust String type
|
|
12
|
-
*/
|
|
13
|
-
export declare const rustString: (property?: string) => unknown;
|
|
14
|
-
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/utils/layout.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,SAAS,yBAA6B,OAclD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,yBAA0B,OA6B5C,CAAC;AAEF,eAAO,MAAM,OAAO,yBAA2B,OA8B9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,yBAA0B,OAyBhD,CAAC"}
|
package/dist/utils/layout.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.rustString = exports.uint128 = exports.uint64 = exports.publicKey = void 0;
|
|
30
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
31
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
32
|
-
const BufferLayout = __importStar(require("buffer-layout"));
|
|
33
|
-
/**
|
|
34
|
-
* Layout for a public key
|
|
35
|
-
*/
|
|
36
|
-
const publicKey = (property = 'publicKey') => {
|
|
37
|
-
const publicKeyLayout = BufferLayout.blob(32, property);
|
|
38
|
-
const _decode = publicKeyLayout.decode.bind(publicKeyLayout);
|
|
39
|
-
const _encode = publicKeyLayout.encode.bind(publicKeyLayout);
|
|
40
|
-
publicKeyLayout.decode = (buffer, offset) => {
|
|
41
|
-
const data = _decode(buffer, offset);
|
|
42
|
-
return new web3_js_1.PublicKey(data);
|
|
43
|
-
};
|
|
44
|
-
publicKeyLayout.encode = (key, buffer, offset) => _encode(key.toBuffer(), buffer, offset);
|
|
45
|
-
return publicKeyLayout;
|
|
46
|
-
};
|
|
47
|
-
exports.publicKey = publicKey;
|
|
48
|
-
/**
|
|
49
|
-
* Layout for a 64bit unsigned value
|
|
50
|
-
*/
|
|
51
|
-
const uint64 = (property = 'uint64') => {
|
|
52
|
-
const layout = BufferLayout.blob(8, property);
|
|
53
|
-
const _decode = layout.decode.bind(layout);
|
|
54
|
-
const _encode = layout.encode.bind(layout);
|
|
55
|
-
layout.decode = (buffer, offset) => {
|
|
56
|
-
const data = _decode(buffer, offset);
|
|
57
|
-
return new bn_js_1.default([...data]
|
|
58
|
-
.reverse()
|
|
59
|
-
.map((i) => `00${i.toString(16)}`.slice(-2))
|
|
60
|
-
.join(''), 16);
|
|
61
|
-
};
|
|
62
|
-
layout.encode = (num, buffer, offset) => {
|
|
63
|
-
const a = num.toArray().reverse();
|
|
64
|
-
let b = Buffer.from(a);
|
|
65
|
-
if (b.length !== 8) {
|
|
66
|
-
const zeroPad = Buffer.alloc(8);
|
|
67
|
-
b.copy(zeroPad);
|
|
68
|
-
b = zeroPad;
|
|
69
|
-
}
|
|
70
|
-
return _encode(b, buffer, offset);
|
|
71
|
-
};
|
|
72
|
-
return layout;
|
|
73
|
-
};
|
|
74
|
-
exports.uint64 = uint64;
|
|
75
|
-
const uint128 = (property = 'uint128') => {
|
|
76
|
-
const layout = BufferLayout.blob(16, property);
|
|
77
|
-
const _decode = layout.decode.bind(layout);
|
|
78
|
-
const _encode = layout.encode.bind(layout);
|
|
79
|
-
layout.decode = (buffer, offset) => {
|
|
80
|
-
const data = _decode(buffer, offset);
|
|
81
|
-
return new bn_js_1.default([...data]
|
|
82
|
-
.reverse()
|
|
83
|
-
.map((i) => `00${i.toString(16)}`.slice(-2))
|
|
84
|
-
.join(''), 16);
|
|
85
|
-
};
|
|
86
|
-
layout.encode = (num, buffer, offset) => {
|
|
87
|
-
const a = num.toArray().reverse();
|
|
88
|
-
let b = Buffer.from(a);
|
|
89
|
-
if (b.length !== 16) {
|
|
90
|
-
const zeroPad = Buffer.alloc(16);
|
|
91
|
-
b.copy(zeroPad);
|
|
92
|
-
b = zeroPad;
|
|
93
|
-
}
|
|
94
|
-
return _encode(b, buffer, offset);
|
|
95
|
-
};
|
|
96
|
-
return layout;
|
|
97
|
-
};
|
|
98
|
-
exports.uint128 = uint128;
|
|
99
|
-
/**
|
|
100
|
-
* Layout for a Rust String type
|
|
101
|
-
*/
|
|
102
|
-
const rustString = (property = 'string') => {
|
|
103
|
-
const rsl = BufferLayout.struct([
|
|
104
|
-
BufferLayout.u32('length'),
|
|
105
|
-
BufferLayout.u32('lengthPadding'),
|
|
106
|
-
BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars'),
|
|
107
|
-
], property);
|
|
108
|
-
const _decode = rsl.decode.bind(rsl);
|
|
109
|
-
const _encode = rsl.encode.bind(rsl);
|
|
110
|
-
rsl.decode = (buffer, offset) => {
|
|
111
|
-
const data = _decode(buffer, offset);
|
|
112
|
-
return data.chars.toString('utf8');
|
|
113
|
-
};
|
|
114
|
-
rsl.encode = (str, buffer, offset) => {
|
|
115
|
-
const data = {
|
|
116
|
-
chars: Buffer.from(str, 'utf8'),
|
|
117
|
-
};
|
|
118
|
-
return _encode(data, buffer, offset);
|
|
119
|
-
};
|
|
120
|
-
return rsl;
|
|
121
|
-
};
|
|
122
|
-
exports.rustString = rustString;
|
|
123
|
-
//# sourceMappingURL=layout.js.map
|
package/dist/utils/layout.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/utils/layout.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4C;AAC5C,kDAAuB;AACvB,4DAA8C;AAE9C;;GAEG;AACI,MAAM,SAAS,GAAG,CAAC,QAAQ,GAAG,WAAW,EA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,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAErC,GAAG,CAAC,MAAM,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE;QAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,GAAG,CAAC,MAAM,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,MAAc,EAAE,EAAE;QAC3D,MAAM,IAAI,GAAG;YACX,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC;SAChC,CAAC;QACF,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAzBW,QAAA,UAAU,cAyBrB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
/**
|
|
3
|
-
* Construct a SyncNative instruction
|
|
4
|
-
*
|
|
5
|
-
* @param account Native account to sync lamports from
|
|
6
|
-
* @param programId SPL Token program account
|
|
7
|
-
*
|
|
8
|
-
* @return Instruction to add to a transaction
|
|
9
|
-
*/
|
|
10
|
-
export declare function syncNative(account: PublicKey, programId?: PublicKey): TransactionInstruction;
|
|
11
|
-
//# sourceMappingURL=syncNative.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncNative.d.ts","sourceRoot":"","sources":["../../src/utils/syncNative.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAKpE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,YAAmB,GAAG,sBAAsB,CAOnG"}
|
package/dist/utils/syncNative.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.syncNative = syncNative;
|
|
27
|
-
const BufferLayout = __importStar(require("buffer-layout"));
|
|
28
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
29
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
30
|
-
const dataLayout = BufferLayout.struct([BufferLayout.u8('instruction')]);
|
|
31
|
-
/**
|
|
32
|
-
* Construct a SyncNative instruction
|
|
33
|
-
*
|
|
34
|
-
* @param account Native account to sync lamports from
|
|
35
|
-
* @param programId SPL Token program account
|
|
36
|
-
*
|
|
37
|
-
* @return Instruction to add to a transaction
|
|
38
|
-
*/
|
|
39
|
-
function syncNative(account, programId = spl_token_1.TOKEN_PROGRAM_ID) {
|
|
40
|
-
const keys = [{ pubkey: account, isSigner: false, isWritable: true }];
|
|
41
|
-
const data = Buffer.alloc(dataLayout.span);
|
|
42
|
-
dataLayout.encode({ instruction: 17 }, data);
|
|
43
|
-
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=syncNative.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"syncNative.js","sourceRoot":"","sources":["../../src/utils/syncNative.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAcA,gCAOC;AArBD,4DAA8C;AAC9C,6CAAoE;AACpE,iDAAqD;AAErD,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAEzE;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,OAAkB,EAAE,SAAS,GAAG,4BAAgB;IACzE,MAAM,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3C,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;IAE7C,OAAO,IAAI,gCAAsB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/D,CAAC"}
|
package/src/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'buffer-layout';
|
package/src/utils/layout.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import BN from 'bn.js';
|
|
3
|
-
import * as BufferLayout from 'buffer-layout';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Layout for a public key
|
|
7
|
-
*/
|
|
8
|
-
export const publicKey = (property = 'publicKey'): unknown => {
|
|
9
|
-
const publicKeyLayout = BufferLayout.blob(32, property);
|
|
10
|
-
|
|
11
|
-
const _decode = publicKeyLayout.decode.bind(publicKeyLayout);
|
|
12
|
-
const _encode = publicKeyLayout.encode.bind(publicKeyLayout);
|
|
13
|
-
|
|
14
|
-
publicKeyLayout.decode = (buffer: Buffer, offset: number) => {
|
|
15
|
-
const data = _decode(buffer, offset);
|
|
16
|
-
return new PublicKey(data);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
publicKeyLayout.encode = (key: PublicKey, buffer: Buffer, offset: number) => _encode(key.toBuffer(), buffer, offset);
|
|
20
|
-
|
|
21
|
-
return publicKeyLayout;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Layout for a 64bit unsigned value
|
|
26
|
-
*/
|
|
27
|
-
export const uint64 = (property = 'uint64'): unknown => {
|
|
28
|
-
const layout = BufferLayout.blob(8, property);
|
|
29
|
-
|
|
30
|
-
const _decode = layout.decode.bind(layout);
|
|
31
|
-
const _encode = layout.encode.bind(layout);
|
|
32
|
-
|
|
33
|
-
layout.decode = (buffer: Buffer, offset: number) => {
|
|
34
|
-
const data = _decode(buffer, offset);
|
|
35
|
-
return new BN(
|
|
36
|
-
[...data]
|
|
37
|
-
.reverse()
|
|
38
|
-
.map((i) => `00${i.toString(16)}`.slice(-2))
|
|
39
|
-
.join(''),
|
|
40
|
-
16
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
layout.encode = (num: BN, buffer: Buffer, offset: number) => {
|
|
45
|
-
const a = num.toArray().reverse();
|
|
46
|
-
let b = Buffer.from(a);
|
|
47
|
-
if (b.length !== 8) {
|
|
48
|
-
const zeroPad = Buffer.alloc(8);
|
|
49
|
-
b.copy(zeroPad);
|
|
50
|
-
b = zeroPad;
|
|
51
|
-
}
|
|
52
|
-
return _encode(b, buffer, offset);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return layout;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const uint128 = (property = 'uint128'): unknown => {
|
|
59
|
-
const layout = BufferLayout.blob(16, property);
|
|
60
|
-
|
|
61
|
-
const _decode = layout.decode.bind(layout);
|
|
62
|
-
const _encode = layout.encode.bind(layout);
|
|
63
|
-
|
|
64
|
-
layout.decode = (buffer: Buffer, offset: number) => {
|
|
65
|
-
const data = _decode(buffer, offset);
|
|
66
|
-
return new BN(
|
|
67
|
-
[...data]
|
|
68
|
-
.reverse()
|
|
69
|
-
.map((i) => `00${i.toString(16)}`.slice(-2))
|
|
70
|
-
.join(''),
|
|
71
|
-
16
|
|
72
|
-
);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
layout.encode = (num: BN, buffer: Buffer, offset: number) => {
|
|
76
|
-
const a = num.toArray().reverse();
|
|
77
|
-
let b = Buffer.from(a);
|
|
78
|
-
if (b.length !== 16) {
|
|
79
|
-
const zeroPad = Buffer.alloc(16);
|
|
80
|
-
b.copy(zeroPad);
|
|
81
|
-
b = zeroPad;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return _encode(b, buffer, offset);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
return layout;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Layout for a Rust String type
|
|
92
|
-
*/
|
|
93
|
-
export const rustString = (property = 'string'): unknown => {
|
|
94
|
-
const rsl = BufferLayout.struct(
|
|
95
|
-
[
|
|
96
|
-
BufferLayout.u32('length'),
|
|
97
|
-
BufferLayout.u32('lengthPadding'),
|
|
98
|
-
BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars'),
|
|
99
|
-
],
|
|
100
|
-
property
|
|
101
|
-
);
|
|
102
|
-
const _decode = rsl.decode.bind(rsl);
|
|
103
|
-
const _encode = rsl.encode.bind(rsl);
|
|
104
|
-
|
|
105
|
-
rsl.decode = (buffer: Buffer, offset: number) => {
|
|
106
|
-
const data = _decode(buffer, offset);
|
|
107
|
-
return data.chars.toString('utf8');
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
rsl.encode = (str: string, buffer: Buffer, offset: number) => {
|
|
111
|
-
const data = {
|
|
112
|
-
chars: Buffer.from(str, 'utf8'),
|
|
113
|
-
};
|
|
114
|
-
return _encode(data, buffer, offset);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
return rsl;
|
|
118
|
-
};
|
package/src/utils/syncNative.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as BufferLayout from 'buffer-layout';
|
|
2
|
-
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
3
|
-
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
4
|
-
|
|
5
|
-
const dataLayout = BufferLayout.struct([BufferLayout.u8('instruction')]);
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Construct a SyncNative instruction
|
|
9
|
-
*
|
|
10
|
-
* @param account Native account to sync lamports from
|
|
11
|
-
* @param programId SPL Token program account
|
|
12
|
-
*
|
|
13
|
-
* @return Instruction to add to a transaction
|
|
14
|
-
*/
|
|
15
|
-
export function syncNative(account: PublicKey, programId = TOKEN_PROGRAM_ID): TransactionInstruction {
|
|
16
|
-
const keys = [{ pubkey: account, isSigner: false, isWritable: true }];
|
|
17
|
-
|
|
18
|
-
const data = Buffer.alloc(dataLayout.span);
|
|
19
|
-
dataLayout.encode({ instruction: 17 }, data);
|
|
20
|
-
|
|
21
|
-
return new TransactionInstruction({ keys, programId, data });
|
|
22
|
-
}
|