@coinbase/cdp-sdk 1.8.0 → 1.10.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 +16 -0
- package/README.md +190 -105
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +7 -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 +2 -0
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/evm/constants.js +21 -0
- package/_cjs/client/evm/constants.js.map +1 -0
- package/_cjs/client/evm/evm.js +75 -0
- package/_cjs/client/evm/evm.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 +14 -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 +26 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.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/policies/schema.js +60 -1
- package/_cjs/policies/schema.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_cjs/version.js.map +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +7 -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 +2 -0
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/evm/constants.js +18 -0
- package/_esm/client/evm/constants.js.map +1 -0
- package/_esm/client/evm/evm.js +75 -0
- package/_esm/client/evm/evm.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 +12 -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 +23 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.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/policies/schema.js +59 -0
- package/_esm/policies/schema.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_esm/version.js.map +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/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 +7 -52
- 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.map +1 -1
- package/_types/client/evm/constants.d.ts +5 -0
- package/_types/client/evm/constants.d.ts.map +1 -0
- package/_types/client/evm/evm.d.ts +44 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +13 -1
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +106 -17
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +7 -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 +2 -0
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.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/index.d.ts +2 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +630 -0
- package/_types/policies/schema.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/_types/version.d.ts.map +1 -1
- package/accounts/evm/toEvmServerAccount.ts +7 -6
- package/accounts/evm/toEvmSmartAccount.ts +1 -2
- package/accounts/solana/toSolanaAccount.ts +7 -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 +8 -66
- 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 +2 -0
- package/client/evm/constants.ts +17 -0
- package/client/evm/evm.ts +90 -0
- package/client/evm/evm.types.ts +14 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +146 -18
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +41 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +20 -0
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
- package/package.json +2 -1
- package/policies/schema.ts +83 -0
- package/version.ts +1 -1
package/_cjs/policies/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UpdatePolicyBodySchema = exports.CreatePolicyBodySchema = exports.PolicyScopeEnum = exports.RuleSchema = exports.SignSolTransactionRuleSchema = exports.SignEvmTransactionRuleSchema = exports.ActionEnum = exports.EvmOperationEnum = exports.SolOperationEnum = exports.SignSolTransactionCriteriaSchema = exports.SignEvmTransactionCriteriaSchema = exports.SolAddressCriterionSchema = exports.EvmAddressCriterionSchema = exports.EthValueCriterionSchema = exports.SolAddressOperatorEnum = exports.EvmAddressOperatorEnum = exports.EthValueOperatorEnum = void 0;
|
|
3
|
+
exports.UpdatePolicyBodySchema = exports.CreatePolicyBodySchema = exports.PolicyScopeEnum = exports.RuleSchema = exports.SignSolTransactionRuleSchema = exports.SendEvmTransactionRuleSchema = exports.SignEvmTransactionRuleSchema = exports.ActionEnum = exports.EvmOperationEnum = exports.SolOperationEnum = exports.SignSolTransactionCriteriaSchema = exports.SendEvmTransactionCriteriaSchema = exports.SignEvmTransactionCriteriaSchema = exports.SolAddressCriterionSchema = exports.EvmNetworkCriterionSchema = exports.EvmNetworkEnum = exports.EvmAddressCriterionSchema = exports.EthValueCriterionSchema = exports.SolAddressOperatorEnum = exports.EvmNetworkOperatorEnum = exports.EvmAddressOperatorEnum = exports.EthValueOperatorEnum = void 0;
|
|
4
4
|
const zod_1 = require("abitype/zod");
|
|
5
5
|
const zod_2 = require("zod");
|
|
6
6
|
/**
|
|
@@ -11,6 +11,10 @@ exports.EthValueOperatorEnum = zod_2.z.enum([">", ">=", "<", "<=", "=="]);
|
|
|
11
11
|
* Enum for EvmAddressOperator values
|
|
12
12
|
*/
|
|
13
13
|
exports.EvmAddressOperatorEnum = zod_2.z.enum(["in", "not in"]);
|
|
14
|
+
/**
|
|
15
|
+
* Enum for EvmNetworkOperator values
|
|
16
|
+
*/
|
|
17
|
+
exports.EvmNetworkOperatorEnum = zod_2.z.enum(["in", "not in"]);
|
|
14
18
|
/**
|
|
15
19
|
* Enum for SolAddressOperator values
|
|
16
20
|
*/
|
|
@@ -48,6 +52,28 @@ exports.EvmAddressCriterionSchema = zod_2.z.object({
|
|
|
48
52
|
*/
|
|
49
53
|
operator: exports.EvmAddressOperatorEnum,
|
|
50
54
|
});
|
|
55
|
+
/**
|
|
56
|
+
* Enum for EVM Network values
|
|
57
|
+
*/
|
|
58
|
+
exports.EvmNetworkEnum = zod_2.z.enum(["base", "base-sepolia"]);
|
|
59
|
+
/**
|
|
60
|
+
* Schema for EVM network criterions
|
|
61
|
+
*/
|
|
62
|
+
exports.EvmNetworkCriterionSchema = zod_2.z.object({
|
|
63
|
+
/** The type of criterion, must be "evmAddress" for EVM address-based rules. */
|
|
64
|
+
type: zod_2.z.literal("evmNetwork"),
|
|
65
|
+
/**
|
|
66
|
+
* Array of EVM network identifiers to compare against.
|
|
67
|
+
* Either "base" or "base-sepolia"
|
|
68
|
+
*/
|
|
69
|
+
networks: zod_2.z.array(exports.EvmNetworkEnum),
|
|
70
|
+
/**
|
|
71
|
+
* The operator to use for evaluating transaction network.
|
|
72
|
+
* "in" checks if a network is in the provided list.
|
|
73
|
+
* "not in" checks if a network is not in the provided list.
|
|
74
|
+
*/
|
|
75
|
+
operator: exports.EvmNetworkOperatorEnum,
|
|
76
|
+
});
|
|
51
77
|
/**
|
|
52
78
|
* Schema for Solana address criterions
|
|
53
79
|
*/
|
|
@@ -73,6 +99,17 @@ exports.SignEvmTransactionCriteriaSchema = zod_2.z
|
|
|
73
99
|
.array(zod_2.z.discriminatedUnion("type", [exports.EthValueCriterionSchema, exports.EvmAddressCriterionSchema]))
|
|
74
100
|
.max(10)
|
|
75
101
|
.min(1);
|
|
102
|
+
/**
|
|
103
|
+
* Schema for criteria used in SendEvmTransaction operations
|
|
104
|
+
*/
|
|
105
|
+
exports.SendEvmTransactionCriteriaSchema = zod_2.z
|
|
106
|
+
.array(zod_2.z.discriminatedUnion("type", [
|
|
107
|
+
exports.EthValueCriterionSchema,
|
|
108
|
+
exports.EvmAddressCriterionSchema,
|
|
109
|
+
exports.EvmNetworkCriterionSchema,
|
|
110
|
+
]))
|
|
111
|
+
.max(10)
|
|
112
|
+
.min(1);
|
|
76
113
|
/**
|
|
77
114
|
* Schema for criteria used in SignSolTransaction operations
|
|
78
115
|
*/
|
|
@@ -113,6 +150,27 @@ exports.SignEvmTransactionRuleSchema = zod_2.z.object({
|
|
|
113
150
|
*/
|
|
114
151
|
criteria: exports.SignEvmTransactionCriteriaSchema,
|
|
115
152
|
});
|
|
153
|
+
/**
|
|
154
|
+
* Type representing a 'sendEvmTransaction' policy rule that can accept or reject specific operations
|
|
155
|
+
* based on a set of criteria.
|
|
156
|
+
*/
|
|
157
|
+
exports.SendEvmTransactionRuleSchema = zod_2.z.object({
|
|
158
|
+
/**
|
|
159
|
+
* Determines whether matching the rule will cause a request to be rejected or accepted.
|
|
160
|
+
* "accept" will allow the transaction, "reject" will block it.
|
|
161
|
+
*/
|
|
162
|
+
action: exports.ActionEnum,
|
|
163
|
+
/**
|
|
164
|
+
* The operation to which this rule applies.
|
|
165
|
+
* Must be "sendEvmTransaction".
|
|
166
|
+
*/
|
|
167
|
+
operation: zod_2.z.literal("sendEvmTransaction"),
|
|
168
|
+
/**
|
|
169
|
+
* The set of criteria that must be matched for this rule to apply.
|
|
170
|
+
* Must be compatible with the specified operation type.
|
|
171
|
+
*/
|
|
172
|
+
criteria: exports.SendEvmTransactionCriteriaSchema,
|
|
173
|
+
});
|
|
116
174
|
/**
|
|
117
175
|
* Type representing a 'signSolTransaction' policy rule that can accept or reject specific operations
|
|
118
176
|
* based on a set of criteria.
|
|
@@ -139,6 +197,7 @@ exports.SignSolTransactionRuleSchema = zod_2.z.object({
|
|
|
139
197
|
*/
|
|
140
198
|
exports.RuleSchema = zod_2.z.discriminatedUnion("operation", [
|
|
141
199
|
exports.SignEvmTransactionRuleSchema,
|
|
200
|
+
exports.SendEvmTransactionRuleSchema,
|
|
142
201
|
exports.SignSolTransactionRuleSchema,
|
|
143
202
|
]);
|
|
144
203
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../policies/schema.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AACtC,6BAAwB;AAExB;;GAEG;AACU,QAAA,oBAAoB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAOzE;;GAEG;AACU,QAAA,sBAAsB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAO/D;;GAEG;AACU,QAAA,sBAAsB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAO/D;;GAEG;AACU,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,gFAAgF;IAChF,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC3B;;;OAGG;IACH,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC;IACtC,8FAA8F;IAC9F,QAAQ,EAAE,4BAAoB;CAC/B,CAAC,CAAC;AAGH;;GAEG;AACU,QAAA,yBAAyB,GAAG,OAAC,CAAC,MAAM,CAAC;IAChD,+EAA+E;IAC/E,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAC7B;;;;OAIG;IACH,SAAS,EAAE,OAAC,CAAC,KAAK,CAAC,aAAO,CAAC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AC,CAAC,CAAC;AAO9D;;GAEG;AACU,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C;;;OAGG;IACH,KAAK,EAAE,uBAAe;IACtB;;;OAGG;IACH,WAAW,EAAE,OAAC;SACX,MAAM,EAAE;SACR,KAAK,CAAC,wBAAwB,CAAC;SAC/B,QAAQ,EAAE;IACb;;;OAGG;IACH,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,kBAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC1C,CAAC,CAAC;AAOU,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C;;;OAGG;IACH,WAAW,EAAE,OAAC;SACX,MAAM,EAAE;SACR,KAAK,CAAC,wBAAwB,CAAC;SAC/B,QAAQ,EAAE;IACb;;;OAGG;IACH,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,kBAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC1C,CAAC,CAAC"}
|
package/_cjs/version.js
CHANGED
package/_cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmServerAccount.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"toEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmServerAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAE1E,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C;QACL,CAAC;QACD,KAAK,CAAC,oBAAoB,CACxB,OAAiE;YAEjE,OAAO,oBAAoB,CAAC,SAAS,EAAE;gBACrC,GAAG,OAAO;gBACV,mBAAmB,EAAE,OAAO,CAAC,OAAO;aACrC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,gBAAgB,CACpB,OAAsD;YAEtD,OAAO,gBAAgB,CAAC,SAAS,EAAE;gBACjC,GAAG,OAAO;gBACV,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,aAAa,CACjB,OAA8C;YAE9C,OAAO,aAAa,CAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { requestFaucet } from "../../actions/solana/requestFaucet.js";
|
|
2
2
|
import { signMessage } from "../../actions/solana/signMessage.js";
|
|
3
3
|
import { signTransaction } from "../../actions/solana/signTransaction.js";
|
|
4
|
+
import { transfer } from "../../actions/solana/transfer.js";
|
|
4
5
|
/**
|
|
5
6
|
* Creates a Solana account instance with actions from an existing Solana account.
|
|
6
7
|
* Use this to interact with previously deployed Solana accounts, rather than creating new ones.
|
|
@@ -33,6 +34,12 @@ export function toSolanaAccount(apiClient, options) {
|
|
|
33
34
|
});
|
|
34
35
|
},
|
|
35
36
|
policies: options.account.policies,
|
|
37
|
+
async transfer(options) {
|
|
38
|
+
return transfer(apiClient, {
|
|
39
|
+
...options,
|
|
40
|
+
from: account.address,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
36
43
|
};
|
|
37
44
|
return account;
|
|
38
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toSolanaAccount.js","sourceRoot":"","sources":["../../../accounts/solana/toSolanaAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"toSolanaAccount.js","sourceRoot":"","sources":["../../../accounts/solana/toSolanaAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAwB,MAAM,kCAAkC,CAAC;AAgBlF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,SAA+B,EAC/B,OAA+B;IAE/B,MAAM,OAAO,GAAkB;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;QAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,KAAK,CAAC,aAAa,CAAC,OAA8C;YAChE,OAAO,aAAa,CAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,OAA4C;YAC5D,OAAO,WAAW,CAAC,SAAS,EAAE;gBAC5B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,eAAe,CACnB,OAAgD;YAEhD,OAAO,eAAe,CAAC,SAAS,EAAE;gBAChC,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;QAClC,KAAK,CAAC,QAAQ,CAAC,OAAsC;YACnD,OAAO,QAAQ,CAAC,SAAS,EAAE;gBACzB,GAAG,OAAO;gBACV,IAAI,EAAE,OAAO,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,73 +1,40 @@
|
|
|
1
|
-
import { encodeFunctionData, erc20Abi
|
|
1
|
+
import { encodeFunctionData, erc20Abi } from "viem";
|
|
2
2
|
import { getErc20Address } from "./utils.js";
|
|
3
3
|
import { serializeEIP1559Transaction } from "../../../utils/serializeTransaction.js";
|
|
4
4
|
export const accountTransferStrategy = {
|
|
5
5
|
executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
network,
|
|
14
|
-
});
|
|
15
|
-
return result.transactionHash;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const erc20Address = getErc20Address(token, network);
|
|
19
|
-
await apiClient.sendEvmTransaction(from.address, {
|
|
20
|
-
transaction: serializeEIP1559Transaction({
|
|
21
|
-
to: erc20Address,
|
|
22
|
-
data: encodeFunctionData({
|
|
23
|
-
abi: erc20Abi,
|
|
24
|
-
functionName: "approve",
|
|
25
|
-
args: [to, value],
|
|
26
|
-
}),
|
|
27
|
-
}),
|
|
28
|
-
network,
|
|
29
|
-
});
|
|
30
|
-
const result = await apiClient.sendEvmTransaction(from.address, {
|
|
31
|
-
transaction: serializeEIP1559Transaction({
|
|
32
|
-
to: erc20Address,
|
|
33
|
-
data: encodeFunctionData({
|
|
34
|
-
abi: erc20Abi,
|
|
35
|
-
functionName: "transfer",
|
|
36
|
-
args: [to, value],
|
|
37
|
-
}),
|
|
38
|
-
}),
|
|
39
|
-
network,
|
|
40
|
-
});
|
|
41
|
-
return result.transactionHash;
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
return transactionHash;
|
|
45
|
-
},
|
|
46
|
-
waitForResult: async ({ publicClient, hash, waitOptions }) => {
|
|
47
|
-
let receipt;
|
|
48
|
-
try {
|
|
49
|
-
receipt = await publicClient.waitForTransactionReceipt({
|
|
50
|
-
hash,
|
|
51
|
-
pollingInterval: waitOptions?.intervalSeconds
|
|
52
|
-
? waitOptions.intervalSeconds * 1000
|
|
53
|
-
: undefined,
|
|
54
|
-
timeout: waitOptions?.timeoutSeconds ? waitOptions.timeoutSeconds * 1000 : undefined,
|
|
6
|
+
if (token === "eth") {
|
|
7
|
+
return apiClient.sendEvmTransaction(from.address, {
|
|
8
|
+
transaction: serializeEIP1559Transaction({
|
|
9
|
+
value,
|
|
10
|
+
to,
|
|
11
|
+
}),
|
|
12
|
+
network,
|
|
55
13
|
});
|
|
56
14
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
15
|
+
const erc20Address = getErc20Address(token, network);
|
|
16
|
+
await apiClient.sendEvmTransaction(from.address, {
|
|
17
|
+
transaction: serializeEIP1559Transaction({
|
|
18
|
+
to: erc20Address,
|
|
19
|
+
data: encodeFunctionData({
|
|
20
|
+
abi: erc20Abi,
|
|
21
|
+
functionName: "approve",
|
|
22
|
+
args: [to, value],
|
|
23
|
+
}),
|
|
24
|
+
}),
|
|
25
|
+
network,
|
|
26
|
+
});
|
|
27
|
+
return apiClient.sendEvmTransaction(from.address, {
|
|
28
|
+
transaction: serializeEIP1559Transaction({
|
|
29
|
+
to: erc20Address,
|
|
30
|
+
data: encodeFunctionData({
|
|
31
|
+
abi: erc20Abi,
|
|
32
|
+
functionName: "transfer",
|
|
33
|
+
args: [to, value],
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
network,
|
|
37
|
+
});
|
|
71
38
|
},
|
|
72
39
|
};
|
|
73
40
|
//# sourceMappingURL=accountTransferStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AAMrF,MAAM,CAAC,MAAM,uBAAuB,GAA0C;IAC5E,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;QACxE,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAChD,WAAW,EAAE,2BAA2B,CAAC;oBACvC,KAAK;oBACL,EAAE;iBACH,CAAC;gBACF,OAAO;aACR,CAA+B,CAAC;QACnC,CAAC;QAED,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAC/C,WAAW,EAAE,2BAA2B,CAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,GAAG,EAAE,QAAQ;oBACb,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAChD,WAAW,EAAE,2BAA2B,CAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,GAAG,EAAE,QAAQ;oBACb,YAAY,EAAE,UAAU;oBACxB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAA+B,CAAC;IACnC,CAAC;CACF,CAAC"}
|
|
@@ -1,66 +1,49 @@
|
|
|
1
1
|
import { encodeFunctionData, erc20Abi } from "viem";
|
|
2
2
|
import { getErc20Address } from "./utils.js";
|
|
3
3
|
import { sendUserOperation } from "../sendUserOperation.js";
|
|
4
|
-
import { waitForUserOperation } from "../waitForUserOperation.js";
|
|
5
4
|
export const smartAccountTransferStrategy = {
|
|
6
5
|
executeTransfer: async ({ apiClient, from, to, value, token, network, paymasterUrl }) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return result.userOpHash;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const erc20Address = getErc20Address(token, network);
|
|
25
|
-
const result = await sendUserOperation(apiClient, {
|
|
26
|
-
smartAccount: from,
|
|
27
|
-
paymasterUrl,
|
|
28
|
-
network,
|
|
29
|
-
calls: [
|
|
30
|
-
{
|
|
31
|
-
to: erc20Address,
|
|
32
|
-
data: encodeFunctionData({
|
|
33
|
-
abi: erc20Abi,
|
|
34
|
-
functionName: "approve",
|
|
35
|
-
args: [to, value],
|
|
36
|
-
}),
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
to: erc20Address,
|
|
40
|
-
data: encodeFunctionData({
|
|
41
|
-
abi: erc20Abi,
|
|
42
|
-
functionName: "transfer",
|
|
43
|
-
args: [to, value],
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
return result.userOpHash;
|
|
49
|
-
}
|
|
50
|
-
})();
|
|
51
|
-
return userOpHash;
|
|
52
|
-
},
|
|
53
|
-
waitForResult: async ({ apiClient, publicClient, from, hash, waitOptions }) => {
|
|
54
|
-
const result = await waitForUserOperation(apiClient, {
|
|
55
|
-
smartAccountAddress: from.address,
|
|
56
|
-
userOpHash: hash,
|
|
57
|
-
waitOptions,
|
|
58
|
-
});
|
|
59
|
-
if (result.status === "complete") {
|
|
60
|
-
return { status: "success", transactionHash: hash };
|
|
6
|
+
if (token === "eth") {
|
|
7
|
+
const result = await sendUserOperation(apiClient, {
|
|
8
|
+
smartAccount: from,
|
|
9
|
+
paymasterUrl,
|
|
10
|
+
network,
|
|
11
|
+
calls: [
|
|
12
|
+
{
|
|
13
|
+
to,
|
|
14
|
+
value,
|
|
15
|
+
data: "0x",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
61
20
|
}
|
|
62
21
|
else {
|
|
63
|
-
|
|
22
|
+
const erc20Address = getErc20Address(token, network);
|
|
23
|
+
const result = await sendUserOperation(apiClient, {
|
|
24
|
+
smartAccount: from,
|
|
25
|
+
paymasterUrl,
|
|
26
|
+
network,
|
|
27
|
+
calls: [
|
|
28
|
+
{
|
|
29
|
+
to: erc20Address,
|
|
30
|
+
data: encodeFunctionData({
|
|
31
|
+
abi: erc20Abi,
|
|
32
|
+
functionName: "approve",
|
|
33
|
+
args: [to, value],
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
to: erc20Address,
|
|
38
|
+
data: encodeFunctionData({
|
|
39
|
+
abi: erc20Abi,
|
|
40
|
+
functionName: "transfer",
|
|
41
|
+
args: [to, value],
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
64
47
|
}
|
|
65
48
|
},
|
|
66
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAK5D,MAAM,CAAC,MAAM,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,iBAAiB,CAAC,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,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAErD,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,SAAS,EAAE;gBAChD,YAAY,EAAE,IAAI;gBAClB,YAAY;gBACZ,OAAO;gBACP,KAAK,EAAE;oBACL;wBACE,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,kBAAkB,CAAC;4BACvB,GAAG,EAAE,QAAQ;4BACb,YAAY,EAAE,SAAS;4BACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;yBAClB,CAAC;qBACH;oBACD;wBACE,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,kBAAkB,CAAC;4BACvB,GAAG,EAAE,QAAQ;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,5 +1,3 @@
|
|
|
1
|
-
import { createPublicClient, http, erc20Abi, parseUnits } from "viem";
|
|
2
|
-
import { mapNetworkToChain } from "./utils.js";
|
|
3
1
|
/**
|
|
4
2
|
* Transfer an amount of a token from an account to another account.
|
|
5
3
|
*
|
|
@@ -10,51 +8,16 @@ import { mapNetworkToChain } from "./utils.js";
|
|
|
10
8
|
* @returns The result of the transfer.
|
|
11
9
|
*/
|
|
12
10
|
export async function transfer(apiClient, from, transferArgs, transferStrategy) {
|
|
13
|
-
const publicClient = createPublicClient({
|
|
14
|
-
chain: mapNetworkToChain(transferArgs.network),
|
|
15
|
-
transport: http(),
|
|
16
|
-
});
|
|
17
11
|
const to = typeof transferArgs.to === "string" ? transferArgs.to : transferArgs.to.address;
|
|
18
|
-
const value = await (async () => {
|
|
19
|
-
// user supplied a bigint. otherwise, we need to convert the amount to a bigint
|
|
20
|
-
if (typeof transferArgs.amount !== "string") {
|
|
21
|
-
return transferArgs.amount;
|
|
22
|
-
}
|
|
23
|
-
const decimals = await (async () => {
|
|
24
|
-
if (transferArgs.token === "eth") {
|
|
25
|
-
return 18;
|
|
26
|
-
}
|
|
27
|
-
else if (transferArgs.token === "usdc") {
|
|
28
|
-
return 6;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return publicClient.readContract({
|
|
32
|
-
address: transferArgs.token,
|
|
33
|
-
abi: erc20Abi,
|
|
34
|
-
functionName: "decimals",
|
|
35
|
-
args: [],
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
return parseUnits(transferArgs.amount, decimals);
|
|
40
|
-
})();
|
|
41
12
|
const transfer = {
|
|
42
13
|
apiClient,
|
|
43
14
|
from,
|
|
44
15
|
to,
|
|
45
|
-
value,
|
|
16
|
+
value: transferArgs.amount,
|
|
46
17
|
token: transferArgs.token,
|
|
47
18
|
network: transferArgs.network,
|
|
48
19
|
paymasterUrl: "paymasterUrl" in transferArgs ? transferArgs.paymasterUrl : undefined,
|
|
49
20
|
};
|
|
50
|
-
|
|
51
|
-
const result = await transferStrategy.waitForResult({
|
|
52
|
-
apiClient,
|
|
53
|
-
publicClient,
|
|
54
|
-
from,
|
|
55
|
-
hash,
|
|
56
|
-
waitOptions: transferArgs.waitOptions,
|
|
57
|
-
});
|
|
58
|
-
return result;
|
|
21
|
+
return transferStrategy.executeTransfer(transfer);
|
|
59
22
|
}
|
|
60
23
|
//# 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":"AAWA;;;;;;;;GAQG;AACH,MAAM,CAAC,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,4 +1,3 @@
|
|
|
1
|
-
import { base, baseSepolia } from "viem/chains";
|
|
2
1
|
/**
|
|
3
2
|
* The address of an ERC20 token for a given network.
|
|
4
3
|
*/
|
|
@@ -22,14 +21,4 @@ const addressMap = {
|
|
|
22
21
|
export function getErc20Address(token, network) {
|
|
23
22
|
return addressMap[network][token] ?? token;
|
|
24
23
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Map a network to a viem chain.
|
|
27
|
-
* TODO: Add more networks (or dynamically map viem chains).
|
|
28
|
-
*
|
|
29
|
-
* @param network - The network to map to a chain.
|
|
30
|
-
* @returns The chain for the given network.
|
|
31
|
-
*/
|
|
32
|
-
export function mapNetworkToChain(network) {
|
|
33
|
-
return network === "base" ? base : baseSepolia;
|
|
34
|
-
}
|
|
35
24
|
//# 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":"AAEA;;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,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,OAAgB;IAC7D,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const GENESIS_HASH_MAINNET = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
2
|
+
export const GENESIS_HASH_DEVNET = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
3
|
+
export const GENESIS_HASH_TESTNET = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
|
4
|
+
export const USDC_MAINNET_MINT_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
5
|
+
export const USDC_DEVNET_MINT_ADDRESS = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../actions/solana/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,8CAA8C,CAAC;AACnF,MAAM,CAAC,MAAM,mBAAmB,GAAG,8CAA8C,CAAC;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,8CAA8C,CAAC;AAEnF,MAAM,CAAC,MAAM,yBAAyB,GAAG,8CAA8C,CAAC;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAAG,8CAA8C,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getMint, getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, createTransferCheckedInstruction, } from "@solana/spl-token";
|
|
2
|
+
import { MessageV0, PublicKey, SystemProgram, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
|
|
3
|
+
import { getConnectedNetwork, getOrCreateConnection, getUsdcMintAddress, } from "./utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Transfers SOL or SPL tokens between accounts
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The API client to use
|
|
8
|
+
* @param options - The transfer options
|
|
9
|
+
*
|
|
10
|
+
* @returns The transfer result
|
|
11
|
+
*/
|
|
12
|
+
export async function transfer(apiClient, options) {
|
|
13
|
+
const connection = getOrCreateConnection({ networkOrConnection: options.network });
|
|
14
|
+
const tx = options.token === "sol"
|
|
15
|
+
? await getNativeTransfer({
|
|
16
|
+
connection,
|
|
17
|
+
from: options.from,
|
|
18
|
+
to: options.to,
|
|
19
|
+
amount: options.amount,
|
|
20
|
+
})
|
|
21
|
+
: await getSplTransfer({
|
|
22
|
+
connection,
|
|
23
|
+
from: options.from,
|
|
24
|
+
to: options.to,
|
|
25
|
+
mintAddress: options.token === "usdc"
|
|
26
|
+
? getUsdcMintAddress(await getConnectedNetwork(connection))
|
|
27
|
+
: options.token,
|
|
28
|
+
amount: options.amount,
|
|
29
|
+
});
|
|
30
|
+
const serializedTx = Buffer.from(tx.serialize()).toString("base64");
|
|
31
|
+
const signedTxResponse = await apiClient.signSolanaTransaction(options.from, {
|
|
32
|
+
transaction: serializedTx,
|
|
33
|
+
});
|
|
34
|
+
const decodedSignedTx = Buffer.from(signedTxResponse.signedTransaction, "base64");
|
|
35
|
+
const signature = await connection.sendRawTransaction(decodedSignedTx, {
|
|
36
|
+
skipPreflight: false,
|
|
37
|
+
maxRetries: 3,
|
|
38
|
+
});
|
|
39
|
+
return { signature };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the instructions for a native SOL transfer
|
|
43
|
+
*
|
|
44
|
+
* @param options - The options for the native SOL transfer
|
|
45
|
+
*
|
|
46
|
+
* @param options.connection - The Solana connection
|
|
47
|
+
* @param options.from - The source address
|
|
48
|
+
* @param options.to - The destination address
|
|
49
|
+
* @param options.amount - The amount to transfer
|
|
50
|
+
*
|
|
51
|
+
* @returns The native SOL transfer transaction
|
|
52
|
+
*/
|
|
53
|
+
async function getNativeTransfer({ connection, from, to, amount, }) {
|
|
54
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
55
|
+
const instructions = [
|
|
56
|
+
SystemProgram.transfer({
|
|
57
|
+
fromPubkey: new PublicKey(from),
|
|
58
|
+
toPubkey: new PublicKey(to),
|
|
59
|
+
lamports: amount,
|
|
60
|
+
}),
|
|
61
|
+
];
|
|
62
|
+
const messageV0 = new TransactionMessage({
|
|
63
|
+
payerKey: new PublicKey(from),
|
|
64
|
+
recentBlockhash: blockhash,
|
|
65
|
+
instructions,
|
|
66
|
+
}).compileToV0Message();
|
|
67
|
+
return new VersionedTransaction(messageV0);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the instructions for a SPL token transfer
|
|
71
|
+
*
|
|
72
|
+
* @param options - The options for the SPL token transfer
|
|
73
|
+
*
|
|
74
|
+
* @param options.connection - The Solana connection
|
|
75
|
+
* @param options.from - The source address
|
|
76
|
+
* @param options.to - The destination address
|
|
77
|
+
* @param options.mintAddress - The mint address of the token
|
|
78
|
+
* @param options.amount - The amount to transfer
|
|
79
|
+
*
|
|
80
|
+
* @returns The SPL token transfer transaction
|
|
81
|
+
*/
|
|
82
|
+
async function getSplTransfer({ connection, from, to, mintAddress, amount, }) {
|
|
83
|
+
const fromPubkey = new PublicKey(from);
|
|
84
|
+
const toPubkey = new PublicKey(to);
|
|
85
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
86
|
+
let mintInfo;
|
|
87
|
+
try {
|
|
88
|
+
mintInfo = await getMint(connection, mintPubkey);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`Failed to fetch mint info for mint address ${mintAddress}. Error: ${error}`);
|
|
92
|
+
}
|
|
93
|
+
const sourceAta = await getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
94
|
+
const destinationAta = await getAssociatedTokenAddress(mintPubkey, toPubkey);
|
|
95
|
+
const instructions = [];
|
|
96
|
+
const sourceAccount = await getAccount(connection, sourceAta);
|
|
97
|
+
if (sourceAccount.amount < amount) {
|
|
98
|
+
throw new Error(`Insufficient token balance. Have ${sourceAccount.amount}, need ${amount}`);
|
|
99
|
+
}
|
|
100
|
+
// Check if destination account exists, if not create it
|
|
101
|
+
try {
|
|
102
|
+
await getAccount(connection, destinationAta);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
instructions.push(createAssociatedTokenAccountInstruction(fromPubkey, destinationAta, toPubkey, mintPubkey));
|
|
106
|
+
}
|
|
107
|
+
instructions.push(createTransferCheckedInstruction(sourceAta, mintPubkey, destinationAta, fromPubkey, amount, mintInfo.decimals));
|
|
108
|
+
return new VersionedTransaction(MessageV0.compile({
|
|
109
|
+
payerKey: fromPubkey,
|
|
110
|
+
instructions: instructions,
|
|
111
|
+
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=transfer.js.map
|