@coinbase/cdp-sdk 1.7.0 → 1.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/CHANGELOG.md +20 -0
- package/README.md +326 -28
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +8 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +30 -63
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/transfer.js +2 -39
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
- package/_cjs/actions/evm/transfer/utils.js +0 -12
- package/_cjs/actions/evm/transfer/utils.js.map +1 -1
- package/_cjs/actions/solana/constants.js +9 -0
- package/_cjs/actions/solana/constants.js.map +1 -0
- package/_cjs/actions/solana/transfer.js +117 -0
- package/_cjs/actions/solana/transfer.js.map +1 -0
- package/_cjs/actions/solana/utils.js +66 -0
- package/_cjs/actions/solana/utils.js.map +1 -0
- package/_cjs/analytics.js +70 -8
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +9 -3
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +133 -15
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/index.js +6 -0
- package/_cjs/client/policies/index.js.map +1 -0
- package/_cjs/client/policies/policies.js +232 -0
- package/_cjs/client/policies/policies.js.map +1 -0
- package/_cjs/client/policies/policies.types.js +3 -0
- package/_cjs/client/policies/policies.types.js.map +1 -0
- package/_cjs/client/solana/solana.js +76 -19
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +4 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +35 -4
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +27 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +56 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +2 -2
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +121 -36
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +14 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +42 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/index.js +6 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/schema.js +245 -0
- package/_cjs/policies/schema.js.map +1 -0
- package/_cjs/policies/types.js +3 -0
- package/_cjs/policies/types.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +4 -2
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +8 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +31 -64
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/transfer.js +2 -39
- package/_esm/actions/evm/transfer/transfer.js.map +1 -1
- package/_esm/actions/evm/transfer/utils.js +0 -11
- package/_esm/actions/evm/transfer/utils.js.map +1 -1
- package/_esm/actions/solana/constants.js +6 -0
- package/_esm/actions/solana/constants.js.map +1 -0
- package/_esm/actions/solana/transfer.js +114 -0
- package/_esm/actions/solana/transfer.js.map +1 -0
- package/_esm/actions/solana/utils.js +61 -0
- package/_esm/actions/solana/utils.js.map +1 -0
- package/_esm/analytics.js +70 -7
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +10 -4
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +133 -15
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/index.js +2 -0
- package/_esm/client/policies/index.js.map +1 -0
- package/_esm/client/policies/policies.js +228 -0
- package/_esm/client/policies/policies.js.map +1 -0
- package/_esm/client/policies/policies.types.js +2 -0
- package/_esm/client/policies/policies.types.js.map +1 -0
- package/_esm/client/solana/solana.js +76 -19
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +34 -3
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +51 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +2 -2
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +116 -35
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +12 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +39 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/index.js +5 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/schema.js +242 -0
- package/_esm/policies/schema.js.map +1 -0
- package/_esm/policies/types.js +2 -0
- package/_esm/policies/types.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +6 -3
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transfer.d.ts +6 -4
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +8 -54
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- package/_types/actions/evm/transfer/utils.d.ts +0 -619
- package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +140 -68
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/constants.d.ts +6 -0
- package/_types/actions/solana/constants.d.ts.map +1 -0
- package/_types/actions/solana/transfer.d.ts +36 -0
- package/_types/actions/solana/transfer.d.ts.map +1 -0
- package/_types/actions/solana/types.d.ts +27 -0
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/solana/utils.d.ts +34 -0
- package/_types/actions/solana/utils.d.ts.map +1 -0
- package/_types/analytics.d.ts +14 -5
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +3 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +89 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +33 -3
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/index.d.ts +2 -0
- package/_types/client/policies/index.d.ts.map +1 -0
- package/_types/client/policies/policies.d.ts +216 -0
- package/_types/client/policies/policies.d.ts.map +1 -0
- package/_types/client/policies/policies.types.d.ts +96 -0
- package/_types/client/policies/policies.types.d.ts.map +1 -0
- package/_types/client/solana/solana.d.ts +43 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +14 -2
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +176 -17
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +3 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +2 -2
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +18 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +1552 -0
- package/_types/policies/schema.d.ts.map +1 -0
- package/_types/policies/types.d.ts +19 -0
- package/_types/policies/types.d.ts.map +1 -0
- package/_types/types/misc.d.ts +39 -0
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +11 -7
- package/accounts/evm/toEvmSmartAccount.ts +1 -2
- package/accounts/evm/types.ts +6 -8
- package/accounts/solana/toSolanaAccount.ts +8 -0
- package/actions/evm/transfer/accountTransferStrategy.ts +38 -78
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +43 -63
- package/actions/evm/transfer/transfer.ts +10 -51
- package/actions/evm/transfer/types.ts +9 -67
- package/actions/evm/transfer/utils.ts +0 -13
- package/actions/evm/types.ts +143 -78
- package/actions/solana/constants.ts +6 -0
- package/actions/solana/transfer.ts +219 -0
- package/actions/solana/types.ts +28 -0
- package/actions/solana/utils.ts +79 -0
- package/analytics.ts +86 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +159 -17
- package/client/evm/evm.types.ts +38 -1
- package/client/policies/index.ts +1 -0
- package/client/policies/policies.ts +246 -0
- package/client/policies/policies.types.ts +109 -0
- package/client/solana/solana.ts +94 -20
- package/client/solana/solana.types.ts +16 -1
- package/index.ts +7 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +220 -18
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +102 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +43 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +3 -1
- package/openapi-client/generated/index.msw.ts +2 -2
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +75 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +23 -0
- package/openapi-client/index.ts +6 -0
- package/package.json +4 -2
- package/policies/schema.ts +349 -0
- package/policies/types.ts +19 -0
- package/types/misc.ts +41 -0
- package/version.ts +1 -1
|
@@ -4,66 +4,49 @@ exports.smartAccountTransferStrategy = void 0;
|
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const sendUserOperation_js_1 = require("../sendUserOperation.js");
|
|
7
|
-
const waitForUserOperation_js_1 = require("../waitForUserOperation.js");
|
|
8
7
|
exports.smartAccountTransferStrategy = {
|
|
9
8
|
executeTransfer: async ({ apiClient, from, to, value, token, network, paymasterUrl }) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return result.userOpHash;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const erc20Address = (0, utils_js_1.getErc20Address)(token, network);
|
|
28
|
-
const result = await (0, sendUserOperation_js_1.sendUserOperation)(apiClient, {
|
|
29
|
-
smartAccount: from,
|
|
30
|
-
paymasterUrl,
|
|
31
|
-
network,
|
|
32
|
-
calls: [
|
|
33
|
-
{
|
|
34
|
-
to: erc20Address,
|
|
35
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
36
|
-
abi: viem_1.erc20Abi,
|
|
37
|
-
functionName: "approve",
|
|
38
|
-
args: [to, value],
|
|
39
|
-
}),
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
to: erc20Address,
|
|
43
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
44
|
-
abi: viem_1.erc20Abi,
|
|
45
|
-
functionName: "transfer",
|
|
46
|
-
args: [to, value],
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
return result.userOpHash;
|
|
52
|
-
}
|
|
53
|
-
})();
|
|
54
|
-
return userOpHash;
|
|
55
|
-
},
|
|
56
|
-
waitForResult: async ({ apiClient, publicClient, from, hash, waitOptions }) => {
|
|
57
|
-
const result = await (0, waitForUserOperation_js_1.waitForUserOperation)(apiClient, {
|
|
58
|
-
smartAccountAddress: from.address,
|
|
59
|
-
userOpHash: hash,
|
|
60
|
-
waitOptions,
|
|
61
|
-
});
|
|
62
|
-
if (result.status === "complete") {
|
|
63
|
-
return { status: "success", transactionHash: hash };
|
|
9
|
+
if (token === "eth") {
|
|
10
|
+
const result = await (0, sendUserOperation_js_1.sendUserOperation)(apiClient, {
|
|
11
|
+
smartAccount: from,
|
|
12
|
+
paymasterUrl,
|
|
13
|
+
network,
|
|
14
|
+
calls: [
|
|
15
|
+
{
|
|
16
|
+
to,
|
|
17
|
+
value,
|
|
18
|
+
data: "0x",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
64
23
|
}
|
|
65
24
|
else {
|
|
66
|
-
|
|
25
|
+
const erc20Address = (0, utils_js_1.getErc20Address)(token, network);
|
|
26
|
+
const result = await (0, sendUserOperation_js_1.sendUserOperation)(apiClient, {
|
|
27
|
+
smartAccount: from,
|
|
28
|
+
paymasterUrl,
|
|
29
|
+
network,
|
|
30
|
+
calls: [
|
|
31
|
+
{
|
|
32
|
+
to: erc20Address,
|
|
33
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
34
|
+
abi: viem_1.erc20Abi,
|
|
35
|
+
functionName: "approve",
|
|
36
|
+
args: [to, value],
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
to: erc20Address,
|
|
41
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
42
|
+
abi: viem_1.erc20Abi,
|
|
43
|
+
functionName: "transfer",
|
|
44
|
+
args: [to, value],
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
67
50
|
}
|
|
68
51
|
},
|
|
69
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAAoD;
|
|
1
|
+
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAAoD;AAEpD,yCAA6C;AAC7C,kEAA4D;AAK/C,QAAA,4BAA4B,GAA+C;IACtF,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE;QACtF,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,MAAM,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAChD,YAAY,EAAE,IAAI;gBAClB,YAAY;gBACZ,OAAO;gBACP,KAAK,EAAE;oBACL;wBACE,EAAE;wBACF,KAAK;wBACL,IAAI,EAAE,IAAI;qBACX;iBACF;aACF,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,MAAM,YAAY,GAAG,IAAA,0BAAe,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAErD,MAAM,MAAM,GAAG,MAAM,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAChD,YAAY,EAAE,IAAI;gBAClB,YAAY;gBACZ,OAAO;gBACP,KAAK,EAAE;oBACL;wBACE,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;4BACvB,GAAG,EAAE,eAAQ;4BACb,YAAY,EAAE,SAAS;4BACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;yBAClB,CAAC;qBACH;oBACD;wBACE,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;4BACvB,GAAG,EAAE,eAAQ;4BACb,YAAY,EAAE,UAAU;4BACxB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;yBAClB,CAAC;qBACH;iBACF;aACF,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transfer = transfer;
|
|
4
|
-
const viem_1 = require("viem");
|
|
5
|
-
const utils_js_1 = require("./utils.js");
|
|
6
4
|
/**
|
|
7
5
|
* Transfer an amount of a token from an account to another account.
|
|
8
6
|
*
|
|
@@ -13,51 +11,16 @@ const utils_js_1 = require("./utils.js");
|
|
|
13
11
|
* @returns The result of the transfer.
|
|
14
12
|
*/
|
|
15
13
|
async function transfer(apiClient, from, transferArgs, transferStrategy) {
|
|
16
|
-
const publicClient = (0, viem_1.createPublicClient)({
|
|
17
|
-
chain: (0, utils_js_1.mapNetworkToChain)(transferArgs.network),
|
|
18
|
-
transport: (0, viem_1.http)(),
|
|
19
|
-
});
|
|
20
14
|
const to = typeof transferArgs.to === "string" ? transferArgs.to : transferArgs.to.address;
|
|
21
|
-
const value = await (async () => {
|
|
22
|
-
// user supplied a bigint. otherwise, we need to convert the amount to a bigint
|
|
23
|
-
if (typeof transferArgs.amount !== "string") {
|
|
24
|
-
return transferArgs.amount;
|
|
25
|
-
}
|
|
26
|
-
const decimals = await (async () => {
|
|
27
|
-
if (transferArgs.token === "eth") {
|
|
28
|
-
return 18;
|
|
29
|
-
}
|
|
30
|
-
else if (transferArgs.token === "usdc") {
|
|
31
|
-
return 6;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return publicClient.readContract({
|
|
35
|
-
address: transferArgs.token,
|
|
36
|
-
abi: viem_1.erc20Abi,
|
|
37
|
-
functionName: "decimals",
|
|
38
|
-
args: [],
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
})();
|
|
42
|
-
return (0, viem_1.parseUnits)(transferArgs.amount, decimals);
|
|
43
|
-
})();
|
|
44
15
|
const transfer = {
|
|
45
16
|
apiClient,
|
|
46
17
|
from,
|
|
47
18
|
to,
|
|
48
|
-
value,
|
|
19
|
+
value: transferArgs.amount,
|
|
49
20
|
token: transferArgs.token,
|
|
50
21
|
network: transferArgs.network,
|
|
51
22
|
paymasterUrl: "paymasterUrl" in transferArgs ? transferArgs.paymasterUrl : undefined,
|
|
52
23
|
};
|
|
53
|
-
|
|
54
|
-
const result = await transferStrategy.waitForResult({
|
|
55
|
-
apiClient,
|
|
56
|
-
publicClient,
|
|
57
|
-
from,
|
|
58
|
-
hash,
|
|
59
|
-
waitOptions: transferArgs.waitOptions,
|
|
60
|
-
});
|
|
61
|
-
return result;
|
|
24
|
+
return transferStrategy.executeTransfer(transfer);
|
|
62
25
|
}
|
|
63
26
|
//# sourceMappingURL=transfer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/transfer.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/transfer.ts"],"names":[],"mappings":";;AAoBA,4BAoBC;AA7BD;;;;;;;;GAQG;AACI,KAAK,UAAU,QAAQ,CAC5B,SAA+B,EAC/B,IAAO,EACP,YAAuF,EACvF,gBAA8C;IAE9C,MAAM,EAAE,GACN,OAAO,YAAY,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAE,YAAY,CAAC,EAAE,CAAC,OAAmB,CAAC;IAE/F,MAAM,QAAQ,GAAG;QACf,SAAS;QACT,IAAI;QACJ,EAAE;QACF,KAAK,EAAE,YAAY,CAAC,MAAM;QAC1B,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,YAAY,EAAE,cAAc,IAAI,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;KACrF,CAAC;IAEF,OAAO,gBAAgB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getErc20Address = getErc20Address;
|
|
4
|
-
exports.mapNetworkToChain = mapNetworkToChain;
|
|
5
|
-
const chains_1 = require("viem/chains");
|
|
6
4
|
/**
|
|
7
5
|
* The address of an ERC20 token for a given network.
|
|
8
6
|
*/
|
|
@@ -26,14 +24,4 @@ const addressMap = {
|
|
|
26
24
|
function getErc20Address(token, network) {
|
|
27
25
|
return addressMap[network][token] ?? token;
|
|
28
26
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Map a network to a viem chain.
|
|
31
|
-
* TODO: Add more networks (or dynamically map viem chains).
|
|
32
|
-
*
|
|
33
|
-
* @param network - The network to map to a chain.
|
|
34
|
-
* @returns The chain for the given network.
|
|
35
|
-
*/
|
|
36
|
-
function mapNetworkToChain(network) {
|
|
37
|
-
return network === "base" ? chains_1.base : chains_1.baseSepolia;
|
|
38
|
-
}
|
|
39
27
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/utils.ts"],"names":[],"mappings":";;AAuBA,0CAEC;AAvBD;;GAEG;AACH,MAAM,UAAU,GAAG;IACjB,IAAI,EAAE;QACJ,IAAI,EAAE,4CAA4C;KACnD;IACD,cAAc,EAAE;QACd,IAAI,EAAE,4CAA4C;KACnD;CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,KAAa,EAAE,OAAgB;IAC7D,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USDC_DEVNET_MINT_ADDRESS = exports.USDC_MAINNET_MINT_ADDRESS = exports.GENESIS_HASH_TESTNET = exports.GENESIS_HASH_DEVNET = exports.GENESIS_HASH_MAINNET = void 0;
|
|
4
|
+
exports.GENESIS_HASH_MAINNET = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
5
|
+
exports.GENESIS_HASH_DEVNET = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
6
|
+
exports.GENESIS_HASH_TESTNET = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
|
7
|
+
exports.USDC_MAINNET_MINT_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
8
|
+
exports.USDC_DEVNET_MINT_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../actions/solana/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,8CAA8C,CAAC;AACtE,QAAA,mBAAmB,GAAG,8CAA8C,CAAC;AACrE,QAAA,oBAAoB,GAAG,8CAA8C,CAAC;AAEtE,QAAA,yBAAyB,GAAG,8CAA8C,CAAC;AAC3E,QAAA,wBAAwB,GAAG,8CAA8C,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transfer = transfer;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Transfers SOL or SPL tokens between accounts
|
|
9
|
+
*
|
|
10
|
+
* @param apiClient - The API client to use
|
|
11
|
+
* @param options - The transfer options
|
|
12
|
+
*
|
|
13
|
+
* @returns The transfer result
|
|
14
|
+
*/
|
|
15
|
+
async function transfer(apiClient, options) {
|
|
16
|
+
const connection = (0, utils_js_1.getOrCreateConnection)({ networkOrConnection: options.network });
|
|
17
|
+
const tx = options.token === "sol"
|
|
18
|
+
? await getNativeTransfer({
|
|
19
|
+
connection,
|
|
20
|
+
from: options.from,
|
|
21
|
+
to: options.to,
|
|
22
|
+
amount: options.amount,
|
|
23
|
+
})
|
|
24
|
+
: await getSplTransfer({
|
|
25
|
+
connection,
|
|
26
|
+
from: options.from,
|
|
27
|
+
to: options.to,
|
|
28
|
+
mintAddress: options.token === "usdc"
|
|
29
|
+
? (0, utils_js_1.getUsdcMintAddress)(await (0, utils_js_1.getConnectedNetwork)(connection))
|
|
30
|
+
: options.token,
|
|
31
|
+
amount: options.amount,
|
|
32
|
+
});
|
|
33
|
+
const serializedTx = Buffer.from(tx.serialize()).toString("base64");
|
|
34
|
+
const signedTxResponse = await apiClient.signSolanaTransaction(options.from, {
|
|
35
|
+
transaction: serializedTx,
|
|
36
|
+
});
|
|
37
|
+
const decodedSignedTx = Buffer.from(signedTxResponse.signedTransaction, "base64");
|
|
38
|
+
const signature = await connection.sendRawTransaction(decodedSignedTx, {
|
|
39
|
+
skipPreflight: false,
|
|
40
|
+
maxRetries: 3,
|
|
41
|
+
});
|
|
42
|
+
return { signature };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets the instructions for a native SOL transfer
|
|
46
|
+
*
|
|
47
|
+
* @param options - The options for the native SOL transfer
|
|
48
|
+
*
|
|
49
|
+
* @param options.connection - The Solana connection
|
|
50
|
+
* @param options.from - The source address
|
|
51
|
+
* @param options.to - The destination address
|
|
52
|
+
* @param options.amount - The amount to transfer
|
|
53
|
+
*
|
|
54
|
+
* @returns The native SOL transfer transaction
|
|
55
|
+
*/
|
|
56
|
+
async function getNativeTransfer({ connection, from, to, amount, }) {
|
|
57
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
58
|
+
const instructions = [
|
|
59
|
+
web3_js_1.SystemProgram.transfer({
|
|
60
|
+
fromPubkey: new web3_js_1.PublicKey(from),
|
|
61
|
+
toPubkey: new web3_js_1.PublicKey(to),
|
|
62
|
+
lamports: amount,
|
|
63
|
+
}),
|
|
64
|
+
];
|
|
65
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
66
|
+
payerKey: new web3_js_1.PublicKey(from),
|
|
67
|
+
recentBlockhash: blockhash,
|
|
68
|
+
instructions,
|
|
69
|
+
}).compileToV0Message();
|
|
70
|
+
return new web3_js_1.VersionedTransaction(messageV0);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the instructions for a SPL token transfer
|
|
74
|
+
*
|
|
75
|
+
* @param options - The options for the SPL token transfer
|
|
76
|
+
*
|
|
77
|
+
* @param options.connection - The Solana connection
|
|
78
|
+
* @param options.from - The source address
|
|
79
|
+
* @param options.to - The destination address
|
|
80
|
+
* @param options.mintAddress - The mint address of the token
|
|
81
|
+
* @param options.amount - The amount to transfer
|
|
82
|
+
*
|
|
83
|
+
* @returns The SPL token transfer transaction
|
|
84
|
+
*/
|
|
85
|
+
async function getSplTransfer({ connection, from, to, mintAddress, amount, }) {
|
|
86
|
+
const fromPubkey = new web3_js_1.PublicKey(from);
|
|
87
|
+
const toPubkey = new web3_js_1.PublicKey(to);
|
|
88
|
+
const mintPubkey = new web3_js_1.PublicKey(mintAddress);
|
|
89
|
+
let mintInfo;
|
|
90
|
+
try {
|
|
91
|
+
mintInfo = await (0, spl_token_1.getMint)(connection, mintPubkey);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`Failed to fetch mint info for mint address ${mintAddress}. Error: ${error}`);
|
|
95
|
+
}
|
|
96
|
+
const sourceAta = await (0, spl_token_1.getAssociatedTokenAddress)(mintPubkey, fromPubkey);
|
|
97
|
+
const destinationAta = await (0, spl_token_1.getAssociatedTokenAddress)(mintPubkey, toPubkey);
|
|
98
|
+
const instructions = [];
|
|
99
|
+
const sourceAccount = await (0, spl_token_1.getAccount)(connection, sourceAta);
|
|
100
|
+
if (sourceAccount.amount < amount) {
|
|
101
|
+
throw new Error(`Insufficient token balance. Have ${sourceAccount.amount}, need ${amount}`);
|
|
102
|
+
}
|
|
103
|
+
// Check if destination account exists, if not create it
|
|
104
|
+
try {
|
|
105
|
+
await (0, spl_token_1.getAccount)(connection, destinationAta);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(fromPubkey, destinationAta, toPubkey, mintPubkey));
|
|
109
|
+
}
|
|
110
|
+
instructions.push((0, spl_token_1.createTransferCheckedInstruction)(sourceAta, mintPubkey, destinationAta, fromPubkey, amount, mintInfo.decimals));
|
|
111
|
+
return new web3_js_1.VersionedTransaction(web3_js_1.MessageV0.compile({
|
|
112
|
+
payerKey: fromPubkey,
|
|
113
|
+
instructions: instructions,
|
|
114
|
+
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../actions/solana/transfer.ts"],"names":[],"mappings":";;AA0DA,4BAuCC;AAjGD,iDAM2B;AAC3B,6CAQyB;AAEzB,yCAKoB;AA4BpB;;;;;;;GAOG;AACI,KAAK,UAAU,QAAQ,CAC5B,SAA+B,EAC/B,OAAwB;IAExB,MAAM,UAAU,GAAG,IAAA,gCAAqB,EAAC,EAAE,mBAAmB,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEnF,MAAM,EAAE,GACN,OAAO,CAAC,KAAK,KAAK,KAAK;QACrB,CAAC,CAAC,MAAM,iBAAiB,CAAC;YACtB,UAAU;YACV,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;QACJ,CAAC,CAAC,MAAM,cAAc,CAAC;YACnB,UAAU;YACV,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,WAAW,EACT,OAAO,CAAC,KAAK,KAAK,MAAM;gBACtB,CAAC,CAAC,IAAA,6BAAkB,EAAC,MAAM,IAAA,8BAAmB,EAAC,UAAU,CAAC,CAAC;gBAC3D,CAAC,CAAC,OAAO,CAAC,KAAK;YACnB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IAET,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEpE,MAAM,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,UAAU;QACpB,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,CAAC,MAAM,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAC,SAAS;KACnE,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrCreateConnection = getOrCreateConnection;
|
|
4
|
+
exports.getConnectedNetwork = getConnectedNetwork;
|
|
5
|
+
exports.getUsdcMintAddress = getUsdcMintAddress;
|
|
6
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
7
|
+
const constants_js_1 = require("./constants.js");
|
|
8
|
+
/**
|
|
9
|
+
* Get a connection to the Solana network
|
|
10
|
+
*
|
|
11
|
+
* @param options - The options for the connection
|
|
12
|
+
*
|
|
13
|
+
* @param options.networkOrConnection - The network to use or a connection
|
|
14
|
+
*
|
|
15
|
+
* @returns The connection
|
|
16
|
+
*/
|
|
17
|
+
function getOrCreateConnection({ networkOrConnection, }) {
|
|
18
|
+
if (typeof networkOrConnection !== "string") {
|
|
19
|
+
return networkOrConnection;
|
|
20
|
+
}
|
|
21
|
+
return new web3_js_1.Connection(networkOrConnection === "mainnet"
|
|
22
|
+
? "https://api.mainnet-beta.solana.com"
|
|
23
|
+
: networkOrConnection === "devnet"
|
|
24
|
+
? "https://api.devnet.solana.com"
|
|
25
|
+
: "https://api.testnet.solana.com");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the network of the connected Solana node
|
|
29
|
+
*
|
|
30
|
+
* @param connection - The connection to the Solana network
|
|
31
|
+
* @throws {Error} If the network is not mainnet, devnet, or testnet
|
|
32
|
+
*
|
|
33
|
+
* @returns The network of the connected Solana node
|
|
34
|
+
*/
|
|
35
|
+
async function getConnectedNetwork(connection) {
|
|
36
|
+
const genesisHash = await connection.getGenesisHash();
|
|
37
|
+
if (genesisHash === constants_js_1.GENESIS_HASH_MAINNET) {
|
|
38
|
+
return "mainnet";
|
|
39
|
+
}
|
|
40
|
+
else if (genesisHash === constants_js_1.GENESIS_HASH_DEVNET) {
|
|
41
|
+
return "devnet";
|
|
42
|
+
}
|
|
43
|
+
else if (genesisHash === constants_js_1.GENESIS_HASH_TESTNET) {
|
|
44
|
+
return "testnet";
|
|
45
|
+
}
|
|
46
|
+
throw new Error("Unknown network");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the USDC mint address for the given connection
|
|
50
|
+
*
|
|
51
|
+
* @param network - The network to use
|
|
52
|
+
*
|
|
53
|
+
* @returns The USDC mint address
|
|
54
|
+
*/
|
|
55
|
+
function getUsdcMintAddress(network) {
|
|
56
|
+
if (network === "mainnet") {
|
|
57
|
+
return constants_js_1.USDC_MAINNET_MINT_ADDRESS;
|
|
58
|
+
}
|
|
59
|
+
else if (network === "devnet") {
|
|
60
|
+
return constants_js_1.USDC_DEVNET_MINT_ADDRESS;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error("Testnet is not supported for USDC");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../actions/solana/utils.ts"],"names":[],"mappings":";;AAyBA,sDAcC;AAUD,kDAYC;AASD,gDAQC;AA9ED,6CAA6C;AAE7C,iDAMwB;AAQxB;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CAAC,EACpC,mBAAmB,GACU;IAC7B,IAAI,OAAO,mBAAmB,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,OAAO,IAAI,oBAAU,CACnB,mBAAmB,KAAK,SAAS;QAC/B,CAAC,CAAC,qCAAqC;QACvC,CAAC,CAAC,mBAAmB,KAAK,QAAQ;YAChC,CAAC,CAAC,+BAA+B;YACjC,CAAC,CAAC,gCAAgC,CACvC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,mBAAmB,CAAC,UAAsB;IAC9D,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,cAAc,EAAE,CAAC;IAEtD,IAAI,WAAW,KAAK,mCAAoB,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,IAAI,WAAW,KAAK,kCAAmB,EAAE,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;SAAM,IAAI,WAAW,KAAK,mCAAoB,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,OAAgB;IACjD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,wCAAyB,CAAC;IACnC,CAAC;SAAM,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,uCAAwB,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
package/_cjs/analytics.js
CHANGED
|
@@ -3,11 +3,18 @@ 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.
|
|
7
|
-
exports.wrapClassWithErrorTracking = wrapClassWithErrorTracking;
|
|
6
|
+
exports.Analytics = void 0;
|
|
8
7
|
const md5_1 = __importDefault(require("md5"));
|
|
8
|
+
const errors_js_1 = require("./openapi-client/errors.js");
|
|
9
|
+
const version_js_1 = require("./version.js");
|
|
9
10
|
// This is a public client id for the analytics service
|
|
10
11
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
12
|
+
exports.Analytics = {
|
|
13
|
+
identifier: "", // set in cdp.ts
|
|
14
|
+
wrapClassWithErrorTracking,
|
|
15
|
+
wrapObjectMethodsWithErrorTracking,
|
|
16
|
+
sendEvent,
|
|
17
|
+
};
|
|
11
18
|
/**
|
|
12
19
|
* Sends an analytics event to the default endpoint
|
|
13
20
|
*
|
|
@@ -15,15 +22,19 @@ const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
|
15
22
|
* @returns Promise that resolves when the event is sent
|
|
16
23
|
*/
|
|
17
24
|
async function sendEvent(event) {
|
|
25
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
18
28
|
const timestamp = Date.now();
|
|
19
29
|
const enhancedEvent = {
|
|
20
|
-
user_id:
|
|
30
|
+
user_id: exports.Analytics.identifier,
|
|
21
31
|
event_type: event.name,
|
|
22
32
|
platform: "server",
|
|
23
33
|
timestamp,
|
|
24
34
|
event_properties: {
|
|
25
35
|
project_name: "cdp-sdk",
|
|
26
36
|
cdp_sdk_language: "typescript",
|
|
37
|
+
version: version_js_1.version,
|
|
27
38
|
...event,
|
|
28
39
|
},
|
|
29
40
|
};
|
|
@@ -52,10 +63,12 @@ async function sendEvent(event) {
|
|
|
52
63
|
* Wraps all methods of a class with error tracking.
|
|
53
64
|
*
|
|
54
65
|
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
55
|
-
* @param apiKeyId - The API key ID to use for the error tracking.
|
|
56
66
|
*/
|
|
57
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
function wrapClassWithErrorTracking(ClassToWrap
|
|
68
|
+
function wrapClassWithErrorTracking(ClassToWrap) {
|
|
69
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
59
72
|
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function");
|
|
60
73
|
for (const method of methods) {
|
|
61
74
|
const originalMethod = ClassToWrap.prototype[method];
|
|
@@ -64,12 +77,46 @@ function wrapClassWithErrorTracking(ClassToWrap, apiKeyId) {
|
|
|
64
77
|
return await originalMethod.apply(this, args);
|
|
65
78
|
}
|
|
66
79
|
catch (error) {
|
|
67
|
-
if (!(error
|
|
68
|
-
|
|
80
|
+
if (!shouldTrackError(error)) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const { message, stack } = error;
|
|
84
|
+
sendEvent({
|
|
85
|
+
method,
|
|
86
|
+
message,
|
|
87
|
+
stack,
|
|
88
|
+
name: "error",
|
|
89
|
+
}).catch(() => {
|
|
90
|
+
// ignore error
|
|
91
|
+
});
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Wraps all methods of an object with error tracking.
|
|
99
|
+
*
|
|
100
|
+
* @param object - The object whose methods should be wrapped.
|
|
101
|
+
*/
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
function wrapObjectMethodsWithErrorTracking(object) {
|
|
104
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const methods = Object.getOwnPropertyNames(object).filter(name => name !== "constructor" && typeof object[name] === "function");
|
|
108
|
+
for (const method of methods) {
|
|
109
|
+
const originalMethod = object[method];
|
|
110
|
+
object[method] = async function (...args) {
|
|
111
|
+
try {
|
|
112
|
+
return await originalMethod.apply(this, args);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (!shouldTrackError(error)) {
|
|
116
|
+
throw error;
|
|
69
117
|
}
|
|
70
118
|
const { message, stack } = error;
|
|
71
119
|
sendEvent({
|
|
72
|
-
apiKeyId,
|
|
73
120
|
method,
|
|
74
121
|
message,
|
|
75
122
|
stack,
|
|
@@ -82,4 +129,19 @@ function wrapClassWithErrorTracking(ClassToWrap, apiKeyId) {
|
|
|
82
129
|
};
|
|
83
130
|
}
|
|
84
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Filters out non-errors and API errors
|
|
134
|
+
*
|
|
135
|
+
* @param error - The error to check.
|
|
136
|
+
* @returns True if the error should be tracked, false otherwise.
|
|
137
|
+
*/
|
|
138
|
+
function shouldTrackError(error) {
|
|
139
|
+
if (!(error instanceof Error)) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (error instanceof errors_js_1.APIError) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
85
147
|
//# sourceMappingURL=analytics.js.map
|
package/_cjs/analytics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../analytics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../analytics.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AAEtB,0DAAsD;AACtD,6CAAuC;AA0BvC,uDAAuD;AACvD,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAE7C,QAAA,SAAS,GAAG;IACvB,UAAU,EAAE,EAAE,EAAE,gBAAgB;IAChC,0BAA0B;IAC1B,kCAAkC;IAClC,SAAS;CACV,CAAC;AAEF;;;;;GAKG;AACH,KAAK,UAAU,SAAS,CAAC,KAAgB;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM,EAAE,CAAC;QACvD,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,MAAM,aAAa,GAAG;QACpB,OAAO,EAAE,iBAAS,CAAC,UAAU;QAC7B,UAAU,EAAE,KAAK,CAAC,IAAI;QACtB,QAAQ,EAAE,QAAQ;QAClB,SAAS;QACT,gBAAgB,EAAE;YAChB,YAAY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AChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC7B,MAAM,KAAK,CAAC;gBACd,CAAC;gBAED,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAc,CAAC;gBAE1C,SAAS,CAAC;oBACR,MAAM;oBACN,OAAO;oBACP,KAAK;oBACL,IAAI,EAAE,OAAO;iBACd,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;oBACZ,eAAe;gBACjB,CAAC,CAAC,CAAC;gBAEH,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,YAAY,oBAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/_cjs/client/cdp.js
CHANGED
|
@@ -5,6 +5,7 @@ const analytics_js_1 = require("../analytics.js");
|
|
|
5
5
|
const index_js_1 = require("../openapi-client/index.js");
|
|
6
6
|
const version_js_1 = require("../version.js");
|
|
7
7
|
const evm_js_1 = require("./evm/evm.js");
|
|
8
|
+
const policies_js_1 = require("./policies/policies.js");
|
|
8
9
|
const solana_js_1 = require("./solana/solana.js");
|
|
9
10
|
/**
|
|
10
11
|
* The main client for interacting with the CDP API.
|
|
@@ -14,6 +15,8 @@ class CdpClient {
|
|
|
14
15
|
evm;
|
|
15
16
|
/** Namespace containing all Solana methods. */
|
|
16
17
|
solana;
|
|
18
|
+
/** Namespace containing all Policies methods. */
|
|
19
|
+
policies;
|
|
17
20
|
/**
|
|
18
21
|
* The CdpClient is the main class for interacting with the CDP API.
|
|
19
22
|
*
|
|
@@ -93,12 +96,15 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
|
|
|
93
96
|
sourceVersion: version_js_1.version,
|
|
94
97
|
});
|
|
95
98
|
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
analytics_js_1.Analytics.identifier = apiKeyId;
|
|
100
|
+
analytics_js_1.Analytics.wrapClassWithErrorTracking(CdpClient);
|
|
101
|
+
analytics_js_1.Analytics.wrapClassWithErrorTracking(evm_js_1.EvmClient);
|
|
102
|
+
analytics_js_1.Analytics.wrapClassWithErrorTracking(solana_js_1.SolanaClient);
|
|
103
|
+
analytics_js_1.Analytics.wrapClassWithErrorTracking(policies_js_1.PoliciesClient);
|
|
99
104
|
}
|
|
100
105
|
this.evm = new evm_js_1.EvmClient();
|
|
101
106
|
this.solana = new solana_js_1.SolanaClient();
|
|
107
|
+
this.policies = new policies_js_1.PoliciesClient();
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
exports.CdpClient = CdpClient;
|
package/_cjs/client/cdp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":";;;AAAA,kDAA4C;AAC5C,yDAA8D;AAC9D,8CAAwC;AACxC,yCAAyC;AACzC,wDAAwD;AACxD,kDAAkD;AAelD;;GAEG;AACH,MAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,CAAY;IAEtB,+CAA+C;IACxC,MAAM,CAAe;IAE5B,iDAAiD;IAC1C,QAAQ,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,YAAY,UAA4B,EAAE;QACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GA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